<?php 
defined('IN_YYS')or exit('Access Denied.');
System::DOWN_App_class('base','member','no');
System::DOWN_App_fun('my','index');
System::DOWN_App_fun('user','index');
System::DOWN_sys_fun('send');
System::DOWN_sys_fun('user');
class home extends base {
	public function __construct(){ 
		parent::__construct();
		if(!$this->userinfo){
			wechat_login();
		}
		
		if(DOWN_A!='userphotoup' and DOWN_A!='singphotoup' and stripos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')==false){
			if(!$this->userinfo) _notemobile("请登录",LOCAL_PATH."/mobile/user/login",3);
		}
        $this->off = $this->db->YOne("select value from `@#_friend` where `name` = 'off'");
        if($this->off['value'] == 1){
            $this->day = $this->db->YOne("select value from `@#_friend` where `name` = 'day'");
        }
		$this->db = System::DOWN_sys_class('model');
		$this->nav = $this->segment(2);
	}
	public function init(){
		$biaoti = "用户中心";
		$index="i4";
		if(!$this->userinfo){
			wechat_login();
		}

	    $webname=$this->_yys['web_name'];
        $huiyuan = $this->userinfo;
        if($this->db->YOne("SELECT stuats from `@#_yonghu_zzzg` where `stuats` = 2 and `uid` = '$huiyuan[uid]'"))
        {
            $huiyuan['zzzg'] = 1;

        }
        if(!$huiyuan['fmoney']){
            $huiyuan['fmoney'] = 0;
        }


		if($huiyuan['uid']){
			$friend = $this->db->YOne("select * from `@#_fanyong` where uid = $huiyuan[uid]");
			if($friend){
				$huiyuan['friend'] = $this->db->YOne("select * from `@#_fanyong_taocan` where id = $friend[taocan_id]");
			}
		}
				

        $this->userinfo = $huiyuan;
		$key2="用户中心";
		//var_dump($key);
		//$quanzi=$this->db->Ylist("select * from `@#_quan_tiezi` order by id DESC LIMIT 5");		
		
	 //获取等级
	  $huiyuandj=$this->db->Ylist("select * from `@#_yonghu_group` where `type` = '会员等级'");
	   
	  $jingyan=$huiyuan['jingyan'];
	  if(!empty($huiyuandj)){
	     foreach($huiyuandj as $key=>$val){
		    if($jingyan>=$val['jingyan_start'] && $jingyan<=$val['jingyan_end']){
			   $huiyuan['level']=$val['name'];
			   $huiyuan['icon']=$val['icon'];
			}
		 }
	  }
		
		$action = 'home';
		include templates("mobile/user","index");
	}
  
	function invite(){
        $webname=$this->_yys['web_name'];
        $huiyuan=$this->userinfo;
        $biaoti="邀请好友";
        //$quanzi=$this->db->Ylist("select * from `@#_quan_tiezi` order by id DESC LIMIT 5");

        //获取惠券等级  惠券新手  惠券小将==
        $huiyuandj=$this->db->Ylist("select * from `@#_yonghu_group`");

        $jingyan=$huiyuan['jingyan'];
        if(!empty($huiyuandj)){
            foreach($huiyuandj as $key=>$val){
                if($jingyan>=$val['jingyan_start'] && $jingyan<=$val['jingyan_end']){
                    $huiyuan['yungoudj']=$val['name'];
                }
            }
        }
        include templates("mobile/user","invite");
    }
	
	  //转帐-对运营者而言存在风险。

	 function zhuanzhang停用(){
		$yonghu=$this->userinfo;
		$title="转帐";
	
		if(isset($_POST['submit1'])){
			
			$tmoney=$_POST[money];
			$tuser=$_POST[txtBankName];
			$tuser1=$_POST[txtBankName1];
		if($tuser!=$tuser1){
			_notemobile("请确认转帐帐号正确",null,3);
		}
			if(empty($tmoney)||empty($tuser))
				_notemobile("转入用户和金额不得为空",null,3);
			if($tmoney>$yonghu[money])
				_notemobile("转入金额不得大于帐户余额",null,3);
			$user= $this->db->YOne("SELECT * FROM `@#_yonghu` where `email` = '$tuser' limit 1");	
			if(empty($user))
				$user= $this->db->YOne("SELECT * FROM `@#_yonghu` where `mobile` = '$tuser' limit 1");	
			if(empty($user))
					_notemobile("转入用户不存在",null,3);
			$uid=$yonghu[uid];
			$tuid=$user[uid];
		if($uid==$tuid)
					_notemobile("不能给自己转帐",null,3);
			$time=time();
			$cmoney=$yonghu[money]-$tmoney;
			$ctmoney=$user[money]+$tmoney;
			$name=huode_user_name($uid,'username','all');
			$tname=huode_user_name($tuid,'username','all');
			

$this->db->Query("update `@#_yonghu` SET `money`='$cmoney' WHERE `uid`='$uid'");
$this->db->Query("update `@#_yonghu` SET `money`='$ctmoney' WHERE `uid`='$tuid'");

$this->db->Query("insert into `@#_yonghu_op_record` (`uid`,`username`,`deltamoney`,`premoney`,`money`,`time`,`guanlian`) values ('$uid','$name','-$tmoney','$yonghu[money]','$cmoney','$time','$tname')");
$this->db->Query("insert into `@#_yonghu_op_record` (`uid`,`username`,`deltamoney`,`premoney`,`money`,`time`,`guanlian`) values ('$tuid','$tname','$tmoney','$user[money]','$ctmoney','$time','$name')");

 $this->db->Query("INSERT INTO `@#_yonghu_zhanghao` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$uid', '-1', '账户', '转出到{$tname}', '$tmoney', '$time')");
  $this->db->Query("INSERT INTO `@#_yonghu_zhanghao` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$tuid', '1', '账户', '由{$name}转入', '$tmoney', '$time')");
				
				
		_notemobile("给".$tname."的".$tmoney."元冲值成功
!",null,3);		
		}
		
		 include templates("mobile/user","zhuanzhang停用");
	}	
	/* 
	public function password(){
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$biaoti="密码修改";	
		include templates("member","password");
	}
	public function oldpassword(){
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		if($huiyuan['password']==md5($_POST['param'])){
			echo '{
					"info":"",
					"status":"y"
				}';
		}else{
			echo "原密码错误";
		}
	}
	public function userpassword(){
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		//$huiyuan=$mysql_model->YOne("select * from `@#_yonghu` where uid='".$huiyuan['uid']."'");	
		$password=isset($_POST['password']) ? $_POST['password'] : "";
		$weerpassword=isset($_POST['userpassword']) ? $_POST['userpassword'] : "";
		$weerpassword2=isset($_POST['userpassword2']) ? $_POST['userpassword2'] : "";
		if($password==null or $weerpassword==null or $weerpassword2==null){
				echo "密码不能为空;";
				exit;
			}
		if($_POST['password']<6 and $_POST['password']<20){
			echo "密码小于6位数";
			exit;
		}
		if($_POST['userpassword']!=$_POST['userpassword2']){
			echo "新密码不一致";
			exit;
		}		
		$password=md5($password);
		$weerpassword=md5($weerpassword);
		if($huiyuan['password']!=$password){
			echo _notemobile("原密码错误",null,3);
		}else{
			$mysql_model->Query("UPDATE `@#_yonghu` SET password='".$weerpassword."' where uid='".$huiyuan['uid']."'");
			echo _notemobile("密码修改成功",null,3);
		}
	} */
	
	
	
		//金币提现开始

	public function mentionnow(){
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$uid=$huiyuan['uid'];
		$biaoti = "金币提现";
		$iii=$this->segment(4);
		$jj=isset($_POST['selectAddrID']) ? $_POST['selectAddrID'] : "";

		$recordmmm=$mysql_model->YOne("select * from `@#_yonghu_yys_record` where `id`='$iii' and `uid`='$huiyuan[uid]' LIMIT 1");	
			
		if(isset($_POST['J_submit'])){
		
			foreach($_POST as $k=>$v){
				$_POST[$k] = _htmtguolv($v);
			}

			$amount=isset($_POST['amount']) ? $_POST['amount'] : "";
			$alipayname=isset($_POST['alipayname']) ? $_POST['alipayname'] : "";
			$alipayusername=isset($_POST['alipayusername']) ? $_POST['alipayusername'] : "";
			$time=time();
			
			
		$shopinfoss=$mysql_model->YOne("select * from `@#_shangpin` where `id`='$recordmmm[shopid]' LIMIT 1");


	//if($recordmmm['leixing']==0)
	if($amount<100)
		{
		_notemobile("金币提现不能小于100",LOCAL_PATH."/mobile/home/cashierSignDeposit",3);
		exit;
	   }
if($amount>$huiyuan['money1']||!is_numeric($amount))
		{
		_notemobile("金币无效,不能提现",LOCAL_PATH."/mobile/home/jifenduihuan",3);
		exit;
	   }
	   $amountsss=$amount*0.01;
	   if($amountsss<10){
	   $shouxufei=$amount*0.01;
	   }else{
		$shouxufei='10';
	   }
	 $hhhh=$amount+$shouxufei;
	   if($hhhh>$huiyuan['money1']){
		   _notemobile("金币不足,不能提现",LOCAL_PATH."/mobile/home/jifenduihuan",3);
		exit;
	   }
	   //手续费
			$mysql_model->Query("UPDATE `@#_yonghu` SET money1=money1-'".$amount."'-'".$shouxufei."' where uid='".$huiyuan['uid']."'");


			 $this->db->Query("INSERT INTO `@#_yonghu_cashout1`(`uid`,`money`,`username`,`bankname`,`branch`,`banknumber`,`linkphone`,`time`,`shenhe`)VALUES
			('$uid','$amount','$alipayname','$alipayusername','$branch','$banknumber','$linkphone','$time','0')"); 
			
			_notemobile("提现申请成功,请等待审核",LOCAL_PATH."/mobile/home/jifenduihuan",3);
		}
	}
	
	//金币提现结束
	
	
	
	
	
	
	
	
	
	
	
	
	

	//改昵称
	public function nicheng(){
		$yonghu=$this->userinfo;
		$uid=$yonghu[uid];
		$title="修改昵称";
		$biaoti = "修改昵称";
		if(is_uploaded_file($_FILES['file_head']['tmp_name'])){
			$upfile=$_FILES["file_head"];
			$name = $upfile["name"];
			$type = $upfile["type"];
			$size = $upfile["size"];
			$tmp_name = $upfile["tmp_name"];
			$error = $upfile["error"];
			switch ($type) {
				case 'image/pjpeg' : $ok=1;
				break;
				case 'image/jpeg' : $ok=1;
				break;
				case 'image/gif' : $ok=1;
				break;
				case 'image/png' : $ok=1;
				break;
			}

			if($ok && $error=='0'){
				$lujing=$_SERVER['DOCUMENT_ROOT']."/statics/uploads/touimg/".date("Ymd")."/";
				$url=$_SERVER['DOCUMENT_ROOT']."/statics/uploads/touimg/".date("Ymd")."/".$yonghu[uid];
				$url1="touimg/".date("Ymd")."/".$yonghu[uid];
				$abcc=substr($name,-4);

				if(!is_dir($lujing)) {
					mkdir($lujing, 0777, true);
				}
				move_uploaded_file($tmp_name,$url.$abcc);

				$copyimages=$url.$abcc;
				$tname=$url1.$abcc;
				$nnimage=$url.$abcc."_160160".$abcc;
				$nnimage1=$url.$abcc."_3030".$abcc;
				$nnimage2=$url.$abcc."_8080".$abcc;
				$nnimage3=$url.$abcc."_30".$abcc;

				copy($copyimages,$nnimage);
				copy($copyimages,$nnimage1);
				copy($copyimages,$nnimage2);
				copy($copyimages,$nnimage3);

				$newimages=$url1.$abcc;
				$this->db->Query("UPDATE `@#_yonghu` SET img='$tname' where uid='$uid'");
			}
		}

		if(isset($_POST['submit1'])){
			$nicheng=$_POST[txtnicheng];
			$time=time();
			$cmoney=$yonghu[money]-$tmoney;
			$ctmoney=$user[money]+$tmoney;
			$name=huode_user_name($uid,'username','all');
			$tname=huode_user_name($tuid,'username','all');
			$this->db->Query("update `@#_yonghu` SET `username`='$nicheng' WHERE `uid`='$uid'");	
			_notemobile("昵称修改成功",LOCAL_PATH."/mobile/home",3);	
		}
		$huiyuan = $yonghu;
		include templates("mobile/user","nicheng");
	}	
	
	//惠券记录
	public function userbuylist(){
	   $webname=$this->_yys['web_name'];
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$uid = $huiyuan['uid'];
		$biaoti="惠券记录";					
		//$record=$mysql_model->Ylist("select * from `@#_yonghu_yys_record` where `uid`='$uid' ORDER BY `time` DESC");				
		include templates("mobile/user","userbuylist");
	}
	//惠券记录详细
	public function userbuydetail(){
	    $webname=$this->_yys['web_name'];
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$biaoti="惠券记录详情";
		$crodid=intval($this->segment(4));
		$record=$mysql_model->YOne("select * from `@#_yonghu_yys_record` where `id`='$crodid' and `uid`='$huiyuan[uid]' LIMIT 1");		
		if($crodid>0){
			include templates("member","userbuydetail");
		}else{
			echo _notemobile("资源不存在",LOCAL_PATH."/member/home/userbuylist",3);
		}
	}
	
	
	//获得的商品
	public function orderlist(){
	    $webname=$this->_yys['web_name'];
		$huiyuan=$this->userinfo;	
		$uid = $huiyuan['uid'];
		$header = "惊喜获得商品，好运时时而来！";
		$biaoti="我的订单";
		include templates("mobile/user","orderlist");
	}
	
	
	//我的订单列表
	public function orderlistzg(){

		$huiyuan=$this->userinfo;	
		$uid = $huiyuan['uid'];
		$biaoti="我的订单";
		$index = 'cart';
		$zongji=$this->db->YCount("select * from `@#_zg_yonghu_yys_record` where `uid`='$uid' and `goucode` = 'zg'");
		$fenye=System::DOWN_sys_class('page');
		if(isset($_GET['p'])){$fenyenum=$_GET['p'];}else{$fenyenum=1;}	
		$fenye->config($zongji,10,$fenyenum,"0");		
		$record = $this->db->YPage("select * from `@#_zg_yonghu_yys_record` where `uid`='$uid' and `goucode` = 'zg' ORDER BY id DESC",array("num"=>10,"page"=>$fenyenum,"type"=>1,"cache"=>0));

		
		//$record=$this->db->Ylist("select * from `@#_yonghu_yys_record` where `uid`='".$huiyuan['uid']."' and `huode`>'10000000' ORDER BY id DESC");
		//$record = $this->db->YPage("select * from `@#_yonghu_yys_record` where `uid`='$uid' and `huode`>'10000000' ORDER BY id DESC",array("num"=>10,"page"=>$fenyenum,"type"=>1,"cache"=>0));
		//var_dump($record);
		include templates("mobile/user","orderlistzg");
	}
	//账户管理
	public function userbalance(){
	    $webname=$this->_yys['web_name'];
		$huiyuan=$this->userinfo;
		$biaoti="账户记录";
		$account=$this->db->Ylist("select * from `@#_yonghu_zhanghao` where `uid`='$huiyuan[uid]' and `pay` = '账户' ORDER BY time DESC");
         $czsum=0;
         $xfsum=0;
		if(!empty($account)){ 
			foreach($account as $key=>$val){
			  if($val['type']==1){
				$czsum+=$val['money'];		  
			  }else{
				$xfsum+=$val['money'];		  
			  }		
			} 		
		}
		
		include templates("mobile/user","userbalance");
	}
	
	 
	public function userrecharge(){
	    $webname = $this->_yys['web_name'];
		$huiyuan = $this->userinfo;
		$biaoti="用户充值";
		$paymentList = $this->db->YList("SELECT pay_id,pay_class,pay_name FROM `@#_payment` WHERE `pay_start` = '1' and `mobile` = '1'");
		include templates("mobile/user","recharge");
	}
	
	
	
	//晒单
	public function singlelist(){
		 $webname=$this->_yys['web_name'];
		include templates("mobile/user","singlelist");
	}	


	//添加晒单
	public function singleinsert(){	
		
		$huiyuan=$this->userinfo;
		$uid=_getcookie('uid');
		$showtime=$uid.date("YmdH");
		$wehell=_getcookie('ushell');
		$biaoti="添加晒单";		
		$lujing=$_SERVER['DOCUMENT_ROOT']."/statics/uploads/shaidan/".date("Ymd")."/";
		$url=$_SERVER['DOCUMENT_ROOT']."/statics/uploads/shaidan/".date("Ymd")."/".$showtime;

		//if($_FILES['Filedata']){
		//		var_dump($_FILES['Filedata']);
		//			exit;
		//}

		$dest_folder   =  $_SERVER['DOCUMENT_ROOT']."/statics/uploads/shaidan/".date("Ymd")."/";   //上传图片保存的路径 图片放在跟你upload.php同级的picture文件夹里
		$arr=array();  //定义一个数组存放上传图片的名称方便你以后会用的，如果不用那就不写
		$count=0; 
		if(!file_exists($dest_folder)){ 
			mkdir($dest_folder);
		} 
		$ggs="";
				
		foreach ($_FILES["Filedata"]["error"] as $key => $error) {
			$_FILES['Filedata1'] = array();
			$_FILES['Filedata1']['tmp_name'] = $_FILES["Filedata"]["tmp_name"][$key];  
			$_FILES['Filedata1']['name'] = $_FILES["Filedata"]["name"][$key];
			$_FILES['Filedata1']['size'] = $_FILES["Filedata"]["size"][$key];
			$_FILES['Filedata1']['type'] = $_FILES["Filedata"]["type"][$key];
			$_FILES['Filedata1']['error'] = $_FILES["Filedata"]["error"][$key];
			$_FILES['Filedata1']['iswatermark'] = 'true';
			
			if($error == UPLOAD_ERR_OK){
				System::DOWN_sys_class('upload','sys','no');
				upload::upload_config(array('png','jpg','jpeg','gif'),10000000,'shaidan');
				upload::go_upload($_FILES['Filedata1']);
				if(!upload::$ok){
					_note(upload::$error,null,3);
				}else{
					$img = upload::$filedir."/".upload::$filename;

					$size = getimagesize(YYS_UPLOADS_PATH."/shaidan/".$img);
					$max=700;$w=$size[0];$h=$size[1];
					if($w>700){
						$w2=$max;
						$h2=$h*($max/$w);
						upload::thumbs($w2,$h2,1);						
					}					
					$arr[$count] = trim("shaidan/".$img);
					$ggs.=trim("shaidan/".$img).";"; 
					$url1 = trim("shaidan/".$img);
					$count++;
				}
			}

		   /*if ($error == UPLOAD_ERR_OK) { 
			$tmp_name = $_FILES["Filedata"]["tmp_name"][$key];  
			$name    = $_FILES["Filedata"]["name"][$key];
			$name1=str_replace('.','', $name);
			$uploadfile = $dest_folder.$name1.$showtime.$key.'.png'; 
			
			 $url1="shaidan/".date("Ymd")."/".$name1.$showtime.$key;
			  $uploadfile1 = $url1.'.png'; 
			move_uploaded_file($tmp_name, $uploadfile);
			$arr[$count]=$uploadfile;
		   // $files=substr($uploadfile,3); //如果你到底的图片名称不是你所要的你可以用截取字符得到
			 $ggs.=$uploadfile1.";"; 
			//echo $files."<br />"; 
			// echo $arr[$count]."<br />";
			 $count++;
			 
			} */

		}

$recordid=intval($this->segment(4));

		//_notemobile("ok");
		$shopid = $recordid;
		$shaidan=$this->db->YOne("select * from `@#_yonghu_yys_record` where `shopid`='$recordid' and `uid` = '$huiyuan[uid]'");
		if(!$shaidan){
			_notemobile("该商品您不可晒单!");
		}
		$shaidanyn=$this->db->YOne("select sd_id from `@#_shai` where `sd_shopid`='$recordid' and `sd_userid` = '$huiyuan[uid]'");
		if($shaidanyn){
			_notemobile("不可重复晒单!");
		}
		$ginfo=$this->db->YOne("select id,sid,qishu,title from `@#_shangpin` where `id`='$shaidan[shopid]' LIMIT 1");
		if(!$ginfo){
			_notemobile("该商品已不存在!");
		}


 
		if(isset($_POST['submit'])){



			if($_POST['title']==null)_notemobile("标题不能为空");	
			if($_POST['content']==null)_notemobile("内容不能为空");	

		//	if(!isset($_POST['fileurl_tmp'])){
		//		_notemobile("图片不能为空");
		//	}

			
			System::DOWN_sys_class('upload','sys','no');
			$img = $_POST['fileurl_tmp'];

			//var_dump($ggs);
			//exit;
			$num=$count;
			$pic="";
			for($i=0;$i<$num;$i++){
				$pic.=trim($img[$i]).";";
			}
			
			$src=trim($img[0]);
			$size=getimagesize(YYS_UPLOADS_PATH."/".$src);
			$width=220;
			$height=$size[1]*($width/$size[0]);

			$thumbs=tubimg($src,$width,$height);				
			$uid=$this->userinfo;
			$sd_userid=$uid['uid'];
			$sd_shopid=$recordid;
			$sd_title=$_POST['title'];
			$sd_thumbs=$url1;
			
			if(empty($ggs)){
				_notemobile("图片不能为空");
				exit;
			}
			
			$sd_content=$_POST['content'];
			$sd_photolist=$ggs;

			$sd_time=time();			
			$this->db->Query("INSERT INTO `@#_shai`(`sd_userid`,`sd_shopid`,`sd_title`,`sd_thumbs`,`sd_content`,`sd_photolist`,`sd_time`)VALUES
			('$sd_userid','$sd_shopid','$sd_title','$sd_thumbs','$sd_content','$sd_photolist','$sd_time')");
			_notemobile("晒单分享成功",LOCAL_PATH."/mobile/home/orderlist");
		}
		$recordid=intval($this->segment(4));
		if($recordid>0){
			$shaidingdan=$this->db->YOne("select * from `@#_yonghu_yys_record` where `id`='$recordid'");		
			$shopid=$shaidingdan['shopid'];
			include templates("mobile/user","singleinsert");
		}else{
			_notemobile("资源不存在");
		}
	}
	//编辑


	//收货地址


	public function address(){
		$dingdancode = $this->segment(4);
		$mysql_model=System::DOWN_sys_class('model');

		$huiyuan=$this->userinfo;
		$biaoti="收货地址";
		$huiyuan_dizhi=$mysql_model->Ylist("select * from `@#_yonghu_dizhi` where uid='".$huiyuan['uid']."' limit 5");
		foreach($huiyuan_dizhi as $k=>$v){		
			$huiyuan_dizhi[$k] = _htmtguolv($v);
		}
		$count=count($huiyuan_dizhi);
		include templates("mobile/user","address");

	}
	
	
	public function deladdress(){
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$id=$this->segment(4);
		$id = abs(intval($id));
		$dizhi=$mysql_model->YOne("select * from `@#_yonghu_dizhi` where `uid`='$huiyuan[uid]' and `id`='$id'");
		if(!empty($dizhi)){
			$mysql_model->Query("DELETE FROM `@#_yonghu_dizhi` WHERE `uid`='$huiyuan[uid]' and `id`='$id'");
			header("location:".LOCAL_PATH."/mobile/home/address");
		}else{
			echo _message("删除失败",LOCAL_PATH."/mobile/home",0);
		}
	}
	
	
	public function updateddress(){
		$biaoti = "更新收货地址";
		$mysql_model=System::DOWN_sys_class('model');

		$huiyuan=$this->userinfo;

		$uid=$huiyuan['uid'];

		$id = $this->segment(4);

		$id = abs(intval($id));

		if(isset($_POST['submit'])){

			$sheng=isset($_POST['sheng']) ? $_POST['sheng'] : "";

			$shi=isset($_POST['shi']) ? $_POST['shi'] : "";

			$xian=isset($_POST['xian']) ? $_POST['xian'] : "";

			$jiedao=isset($_POST['jiedao']) ? $_POST['jiedao'] : "";

			$youbian=isset($_POST['youbian']) ? $_POST['youbian'] : "";

			$shouhuoren=isset($_POST['shouhuoren']) ? $_POST['shouhuoren'] : "";

			$tell=isset($_POST['tell']) ? $_POST['tell'] : "";

			$mobile=isset($_POST['mobile']) ? $_POST['mobile'] : "";

			$qq=isset($_POST['qq']) ? $_POST['qq'] : "";

			$time=time();

			if($sheng==null or $jiedao==null or $shouhuoren==null or $mobile==null){

				echo "带星号不能为空;";

				exit;

			}			

			if(!_checkmobile($mobile)){

				echo "手机号错误;";

				exit;

			}

		$mysql_model->Query("UPDATE `@#_yonghu_dizhi` SET 

		`uid`='".$uid."',		

		`sheng`='".$sheng."',

		`shi`='".$shi."',

		`xian`='".$xian."',

		`jiedao`='".$jiedao."',

		`youbian`='".$youbian."',

		`shouhuoren`='".$shouhuoren."',

		`tell`='".$tell."',

		`qq`='".$qq."',

		`mobile`='".$mobile."' where `id`='".$id."'");				

		_notemobile("修改成功",LOCAL_PATH."/mobile/home/address",3);

		}

	}
	public function useraddress(){

		$mysql_model=System::DOWN_sys_class('model');

		$huiyuan=$this->userinfo;

		$uid=$huiyuan['uid'];

		if(isset($_POST['submit'])){

			foreach($_POST as $k=>$v){

				$_POST[$k] = _htmtguolv($v);

			}

			$sheng=isset($_POST['sheng']) ? $_POST['sheng'] : "";

			$shi=isset($_POST['shi']) ? $_POST['shi'] : "";

			$xian=isset($_POST['xian']) ? $_POST['xian'] : "";

			$jiedao=isset($_POST['jiedao']) ? $_POST['jiedao'] : "";

			$youbian=isset($_POST['youbian']) ? $_POST['youbian'] : "";

			$shouhuoren=isset($_POST['shouhuoren']) ? $_POST['shouhuoren'] : "";

			$tell=isset($_POST['tell']) ? $_POST['tell'] : "";

			$mobile=isset($_POST['mobile']) ? $_POST['mobile'] : "";

			$qq=isset($_POST['qq']) ? $_POST['qq'] : "";

			$time=time();

			if($sheng==null or $jiedao==null or $shouhuoren==null or $mobile==null){

				echo "带星号不能为空;";

				exit;

			}			

			if(!_checkmobile($mobile)){

				echo "手机号错误;";

				exit;

			}

			$huiyuan_dizhi=$mysql_model->YOne("select * from `@#_yonghu_dizhi` where `uid`='".$huiyuan['uid']."'");

			if(!$huiyuan_dizhi){

				$default="Y";

			}else{

				$default="N";

			}

			$mysql_model->Query("INSERT INTO `@#_yonghu_dizhi`(`uid`,`sheng`,`shi`,`xian`,`jiedao`,`youbian`,`shouhuoren`,`tell`,`mobile`,`qq`,`default`,`time`)VALUES

			('$uid','$sheng','$shi','$xian','$jiedao','$youbian','$shouhuoren','$tell','$mobile','$qq','$default','$time')");

			_notemobile("收货地址添加成功",LOCAL_PATH."/mobile/home/address",3);

		}

	}

	//收货地址结束
	public function PostSingleEdit(){
		
		_notemobile("不可编辑!");
		if(isset($_POST['submit'])){
			System::DOWN_sys_class('upload','sys','no');
			if($_POST['title']==null)_notemobile("标题不能为空");	
			if($_POST['content']==null)_notemobile("内容不能为空");				
			$sd_id=$_POST['sd_id'];
			$shaidingdan=$this->db->YOne("select * from `@#_shai` where `sd_id`='$sd_id'");			
			$pic=null;$thumbs=null;
			if(isset($_POST['fileurl_tmp'])){
				if($shaidingdan['sd_photolist']==null){				
					$img=$_POST['fileurl_tmp'];
					$num=count($img);
					for($i=0;$i<$num;$i++){
						$pic.=trim($img[$i]).";";
					}
					$src=trim($img[0]);
					$size=getimagesize(YYS_UPLOADS_PATH."/".$src);
					$width=220;
					$height=$size[1]*($width/$size[0]);			
					$thumbs=tubimg($src,$width,$height);
				}else{
					$img=$_POST['fileurl_tmp'];
					$num=count($img);
					for($i=0;$i<$num;$i++){
						$pic.=$img[$i].";";
					}
				}
			}
			if($thumbs!=null){
				$sd_thumbs=$thumbs;
			}else{
				$sd_thumbs=$shaidingdan['sd_thumbs'];
			}
			$uid=$this->userinfo;
			$sd_userid=$uid['uid'];
			$sd_shopid=$shaidingdan['sd_shopid'];
			$sd_title=$_POST['title'];
			$sd_content=$_POST['content'];
			$sd_photolist=$pic.$shaidingdan['sd_photolist'];
			$sd_time=time();			
			$this->db->Query("UPDATE `@#_shai` SET
			`sd_userid`='$sd_userid',
			`sd_shopid`='$sd_shopid',
			`sd_title`='$sd_title',
			`sd_thumbs`='$sd_thumbs',
			`sd_content`='$sd_content',
			`sd_photolist`='$sd_photolist',
			`sd_time`='$sd_time' where sd_id='$sd_id'");
			_notemobile("晒单修改成功",LOCAL_PATH."/member/home/singlelist");
		}
		$huiyuan=$this->userinfo;
		$biaoti="修改晒单";	
		$uid=_getcookie('uid');
		$wehell=_getcookie('ushell');
		$sd_id=intval($this->segment(4));
		if($sd_id>0){
			$shaidingdan=$this->db->YOne("select * from `@#_shai` where `sd_id`='$sd_id'");
			include templates("member","singleupdate");
		}else{
			_notemobile("资源不存在");
		}	
	}
	public function singoldimg(){
		if($_POST['action']=='del'){
			$sd_id=$_POST['sd_id'];
			$oldimg=$_POST['oldimg'];
			$shaidingdan=$this->db->YOne("select * from `@#_shai` where `sd_id`='$sd_id'");
			$sd_photolist=str_replace($oldimg.";","",$shaidingdan['sd_photolist']);
			$this->db->Query("UPDATE `@#_shai` SET sd_photolist='".$sd_photolist."' where sd_id='".$sd_id."'");
		}
	}
	public function singphotoup(){
		 $mysql_model=System::DOWN_sys_class('model');		
		if(!empty($_FILES)){			
			$uid=isset($_POST['uid']) ? $_POST['uid'] : NULL;		
			$wehell=isset($_POST['ushell']) ? $_POST['ushell'] : NULL;
			$login=$this->checkuser($uid,$wehell);
			if(!$login){_notemobile("上传出错");}
			System::DOWN_sys_class('upload','sys','no');
			upload::upload_config(array('png','jpg','jpeg','gif'),1000000,'shaidan');
			upload::go_upload($_FILES['Filedata']);
			if(!upload::$ok){
				echo _notemobile(upload::$error,null,3);
			}else{
				$img=upload::$filedir."/".upload::$filename;					
				$size=getimagesize(YYS_UPLOADS_PATH."/shaidan/".$img);
				$max=700;$w=$size[0];$h=$size[1];
				if($w>700){
					$w2=$max;
					$h2=$h*($max/$w);
					upload::thumbs($w2,$h2,1);						
				}
					
				echo trim("shaidan/".$img);
			}					
		} 
	}	
	public function singdel(){
		$action=isset($_GET['action']) ? $_GET['action'] : null; 
		$filename=isset($_GET['filename']) ? $_GET['filename'] : null;
		if($action=='del' && !empty($filename)){
			$filename=YYS_UPLOADS_PATH.'shaidan/'.$filename;			
			$size=getimagesize($filename);			
			$filetype=explode('/',$size['mime']);			
			if($filetype[0]!='image'){
				return false;
				exit;
			}
			unlink($filename);
			exit;
		}
	}
	//晒单删除
	public function shaidandel(){
		_notemobile("不可以删除!");
		$huiyuan=$this->userinfo;
		//$id=isset($_GET['id']) ? $_GET['id'] : "";
		$id=$this->segment(4);
		$id=intval($id);
		$shaidingdan=$this->db->YOne("select * from `@#_shai` where `sd_userid`='$huiyuan[uid]' and `sd_id`='$id'");
		if($shaidingdan){
			$this->db->Query("DELETE FROM `@#_shai` WHERE `sd_userid`='$huiyuan[uid]' and `sd_id`='$id'");
			_notemobile("删除成功",LOCAL_PATH."/member/home/singlelist");
		}else{
			_notemobile("删除失败",LOCAL_PATH."/member/home/singlelist");
		}
	}
	
	
 //手机签到

 public function qiandao() {
	 
		# 签到时间限制（不能夸天哦。。）
		$time_start = '00:01';
		$time_stop= '23:59';

		# 每日签到增加福分

		$gg = System::DOWN_App_config("user_fufen");
		
		$time_score = $gg["fufen_yongjinqd"];

		# 连续签到的天数
		$time_day = 60;
		# 连续签到增加的福分
		$time_day_score = rand(100,150);



		$yonghu=$this->userinfo;
		if ( isset($_POST['submit']) ) {
			
			if ( $yonghu['sign_in_date'] == date('Y-m-d') ) {
				_notemobile("您今天已经过签到了。",LOCAL_PATH."/mobile/home/qiandao");

			}else if ( strtotime(date('Y-m-d').$time_start ) > time() || strtotime(date('Y-m-d').$time_stop ) < time() ) {
				_notemobile("现在不是签到时间！签到时间为{$time_start}点到{$time_stop}点",LOCAL_PATH."/mobile/home/qiandao");

			} else {
				$mysql_model = System::DOWN_sys_class('model');
				if ( $yonghu['sign_in_date'] == date('Y-m-d',strtotime('-1 day')) ){
					# 连续签到

					if ( $yonghu['sign_in_time'] >= $time_day ) {
						$yonghu['sign_in_time'] = 0;
					}

					$sign_in_time = $yonghu['sign_in_time'] + 1;
					$sign_in_time_all = $yonghu['sign_in_time_all'] + 1;
					$sign_in_date = date('Y-m-d');
					$score = $yonghu['score'] + $time_score;

					if ( $sign_in_time >= $time_day ) {
						# 领取大礼包了
						$score += $time_day_score;
						$big = true;
					} else {
						$big = false;
					}

					$mysql_model->Query("INSERT INTO `@#_yonghu_zhanghao` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('".$yonghu['uid']."', '1', '福分', '每日签到', '$time_score', '".time()."')");
					$mysql_model->Query("UPDATE `@#_yonghu` SET score='".$score."',sign_in_time='".$sign_in_time."', sign_in_time_all='".$sign_in_time_all."', sign_in_date='".$sign_in_date."' where uid='".$yonghu['uid']."'");
					if ( $big ) {
						$mysql_model->Query("INSERT INTO `@#_yonghu_zhanghao` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('".$yonghu['uid']."', '1', '福分', '签到大礼包', '$time_day_score', '".time()."')");
						_notemobile("签到成功，成功领取{$time_score}福分。<br />恭喜您获得{$time_day_score}福分的大礼包。<br />您的当前福分为{$score}",LOCAL_PATH."/mobile/home/qiandao",10);
					} else {
						_notemobile("签到成功，成功领取{$time_score}福分。<br />您的当前福分为{$score}。<br />再连续签到".($time_day-$sign_in_time)."天就能领取大礼包啦，加油！！！",LOCAL_PATH."/mobile/home/qiandao");
					}

				} else {
					$sign_in_time = 1;
					$sign_in_time_all = $yonghu['sign_in_time_all'] + 1;
					$sign_in_date = date('Y-m-d');
					$score = $yonghu['score'] + $time_score;
					$mysql_model->Query("INSERT INTO `@#_yonghu_zhanghao` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('".$yonghu['uid']."', '1', '福分', '每日签到', '$time_score', '".time()."')");
					$mysql_model->Query("UPDATE `@#_yonghu` SET score='".$score."',sign_in_time='".$sign_in_time."', sign_in_time_all='".$sign_in_time_all."', sign_in_date='".$sign_in_date."' where uid='".$yonghu['uid']."'");
					_notemobile("签到成功，成功领取{$time_score}福分。<br />您的当前福分为{$score}",LOCAL_PATH."/mobile/home/qiandao");
				}
			}
			die;
		}

		if ( !$yonghu['sign_in_date'] ) {
			$yonghu['sign_in_date'] = '-';

		}else if ( $yonghu['sign_in_date'] != date('Y-m-d') && $yonghu['sign_in_date'] != date('Y-m-d',strtotime('-1 day')) ) {

			$yonghu['sign_in_time'] = 0;
		}
		include templates("mobile/user","qiandao");
	}
	
	//添加手机验证送福分及经验重新改造开始
	
		public function mobilechecking(){
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$biaoti="手机验证";
		if($huiyuan['mobile'] && $huiyuan['mobilecode'] == 1){
			_notemobile("登入成功,请关注微信公众号获更多资讯！");
		}	
		include templates("mobile/user","mobilechecking");
	}
	
	//手机验证
	public function mobilesuccess(){
		
		$biaoti="手机验证";
		$huiyuan=$this->userinfo;
		
		if(isset($_POST['submit'])){
			$mobile=isset($_POST['mobile']) ? $_POST['mobile'] : "";
			if(!_checkmobile($mobile) || $mobile==null){
				_notemobile("手机号错误",null,3);	
			}
			$huiyuan2=$this->db->YOne("select mobilecode,uid,mobile from `@#_yonghu` where `mobile`='$mobile' and `uid` != '$huiyuan[uid]'");
			if($huiyuan2 && $huiyuan2['mobilecode'] == 1){
				_notemobile("手机号已被注册！");
			}					
			if($huiyuan['mobilecode']!=1){
				//验证码
				$ok = send_mobile_reg_code($mobile,$huiyuan['uid']);			
				if($ok[0]!=1){
					_notemobile("发送失败,失败状态:".$ok[1]);
				}else{
					_setcookie("mobilecheck",base64_encode($mobile));
				}					
			}
			$time=120;
			include templates("mobile/user","mobilesuccess");
		}
	}
	//重发手机验证码
	public function sendmobile(){
		$huiyuan=$this->userinfo;
		$mobilecodes=rand(100000,999999).'|'.time();//验证码

		if($huiyuan['mobilecode']==1){_notemobile("该账号验证成功",LOCAL_PATH."/mobile/home");}			
		
		$checkcode=explode("|",$huiyuan['mobilecode']);
		$times=time()-$checkcode[1];
		if($times > 120){
			//重发验证码			
				$ok = send_mobile_reg_code($huiyuan['mobile'],$huiyuan['uid']);
				if($ok[0]!=1){
					_notemobile("发送失败,失败状态:".$ok[1]);
				}
			
			_note("正在重新发送...",LOCAL_PATH."/member/user/mobilecheck/"._encrypt($huiyuan['mobile']),2);				
		}else{
			_notemobile("重发时间间隔不能小于2分钟!",LOCAL_PATH."/member/user/mobilecheck/"._encrypt($huiyuan['mobile']));
		}
		
	}
	public function mobilecheck(){	
		$huiyuan=$this->userinfo;
		if(isset($_POST['submit'])){
			$shoujimahao =  base64_decode(_getcookie("mobilecheck"));
			if(!_checkmobile($shoujimahao))_note("手机号码错误!");			
			$checkcodes=isset($_POST['mobile']) ? $_POST['mobile'] : _note("参数不正确!");
			if(strlen($checkcodes)!=6)_note("验证码输入不正确!");
			$weercode=explode("|",$huiyuan['mobilecode']);	

			if($checkcodes!=$weercode[0])_note("验证码输入不正确!");
			$this->db->Query("UPDATE `@#_yonghu` SET `mobilecode`='1',`mobile` = '$shoujimahao' where `uid`='$huiyuan[uid]'");
			//福分、经验添加			
			$isset_user=$this->db->Ylist("select `uid` from `@#_yonghu_zhanghao` where `content`='手机认证完善奖励' and `type`='1' and `uid`='$huiyuan[uid]' and (`pay`='经验' or `pay`='福分')");	
			if(empty($isset_user)){
				$config = System::DOWN_app_config("user_fufen");//福分/经验
				$time=time();
				$this->db->Query("insert into `@#_yonghu_zhanghao` (`uid`,`type`,`pay`,`content`,`money`,`time`) values ('$huiyuan[uid]','1','福分','手机认证完善奖励','$config[f_phonecode]','$time')");
				$this->db->Query("insert into `@#_yonghu_zhanghao` (`uid`,`type`,`pay`,`content`,`money`,`time`) values ('$huiyuan[uid]','1','经验','手机认证完善奖励','$config[z_phonecode]','$time')");			
				$this->db->Query("UPDATE `@#_yonghu` SET `score`=`score`+'$config[f_phonecode]',`jingyan`=`jingyan`+'$config[z_phonecode]' where uid='".$huiyuan['uid']."'");
			}
			_setcookie("uid",_encrypt($huiyuan['uid']));	
			_setcookie("ushell",_encrypt(md5($huiyuan['uid'].$huiyuan['password'].$huiyuan['mobile'].$huiyuan['email'])));		
//福分、经验添加			
			$isset_user=$this->db->YOne("select `uid` from `@#_yonghu_zhanghao` where `pay`='手机认证完善奖励' and `type`='1' and `uid`='$huiyuan[uid]' or `pay`='经验'");	
			if(empty($isset_user)){
				$config = System::DOWN_app_config("user_fufen");//福分/经验
				$time=time();

				$this->db->Query("insert into `@#_yonghu_zhanghao` (`uid`,`type`,`pay`,`content`,`money`,`time`) values ('$huiyuan[uid]','1','福分','手机认证完善奖励','$config[f_overziliao]','$time')");
				$this->db->Query("insert into `@#_yonghu_zhanghao` (`uid`,`type`,`pay`,`content`,`money`,`time`) values ('$huiyuan[uid]','1','经验','手机认证完善奖励','$config[z_overziliao]','$time')");			
				$mysql_model->Query("UPDATE `@#_yonghu` SET `score`=`score`+'$config[f_overziliao]',`jingyan`=`jingyan`+'$config[z_overziliao]' where uid='".$huiyuan['uid']."'");
			}			
			_notemobile("祝贺您，验证成功！<br/>初始密码：123456，请重新登录后修改。",LOCAL_PATH."/mobile/home");
		}else{
			_notemobile("资源不存在",null,3);
		}
	}
	//添加手机验证送福分及经验重新改造结束
	
	
//是否绑定手机号判断
	function accountbind(){
		$member=$this->userinfo;
		   		if(empty($member)){
   			_notemobile("您还未登录，请登陆后再操作");
   			exit();
   		}
		if($member['mobilecode']==1){
			_notemobile("你的帐号已绑定。");
   			exit();
		}
		if(stripos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')!==false){
			include templates("mobile/user","accountbind");
		}
   }

	public function mobilebind(){
		$biaoti="手机验证绑定";
   		$member = $this->userinfo;
   		if(empty($member)){
   			_notemobile("您还未登录，请登陆后再操作",LOCAL_PATH."/mobile/user/login",1);
   			exit();
   		}
		/*if($member['mobilecode']==1){
			_notemobile("谢谢，系统为您返回！");
   			exit();
		}*/
		$header = "系统已自动为您的手机绑定";
		include templates("mobile/user","mobilebind");
   }
   
   
   function mobilebindcheck(){
	   $biaoti="手机验证绑定";
   		$mobile=$this->segment(4);
   		if(!preg_match("/1[34578]{1}\d{9}$/",$mobile)){
		    _notemobile("请输入正确的手机号!");
		    exit;
		}
        $member=$this->userinfo;

		if(!$member){
		    _notemobile("绑定出错!");
			exit;
	    }
		$checkcode=explode("|",$member['mobilecode']);
		$times=time()-$checkcode[1];
		if($times > 120){
			$sendok = send_mobile_reg_code($mobile,$member['uid']);
			if($sendok[0]!=1){
				_notemobile('短信发送失败！');exit;
				exit;
			}

		}
		include templates("mobile/user","mobilebindcheck");
   }



   //fix by dabin

	public function orderDetail(){
		$huiyuan=$this->userinfo;	
		$crodid=intval($this->segment(4));
		$iii=$this->segment(4);
		$biaoti="订单详情";
		$records=$this->db->YOne("select * from `@#_yonghu_yys_record` where `id`='$crodid' and `uid`='$huiyuan[uid]' LIMIT 1");
		$tupian=$this->db->YOne("select * from `@#_shangpin` where `id`='$records[shopid]' LIMIT 1");
		if($records['status']=='已付款,未发货,未完成,未提交地址'){
			$fhid = 0;
		}elseif($records['status']=='已付款,未发货,未完成,已提交地址'){
			$fhid = 1;
		}elseif($records['status']=='已付款,已发货,待收货'){
			$fhid = 2;
		}elseif($records['status']=='已付款,已发货,已完成'){
			$fhid = 3;
		}elseif($records['status']=='已付款,已发货,已作废'){
			$fhid = 4;
		}
		$status=@explode(",",$records['status']); 
		$ii=$this->segment(4);
		$uid = $huiyuan['uid'];
		$biaoti="获得的商品 - "._yys("web_name");
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$biaoti="收货地址";
		$huiyuan_dizhi=$mysql_model->Ylist("select * from `@#_yonghu_dizhi` where uid='".$huiyuan['uid']."'  limit 1");
		$dizhi_sta=$this->db->YOne("select * from `@#_yonghu_yys_record` where id='$iii' limit 1");
		foreach($huiyuan_dizhi as $k=>$v){		
			$huiyuan_dizhi[$k] = _htmtguolv($v);
		}

		$count=count($huiyuan_dizhi);
		$zongji=$this->db->YCount("select * from `@#_yonghu_yys_record` where `uid`='$uid' and `huode`>'10000000'");
		$fenye=System::DOWN_sys_class('page');
		if(isset($_GET['p'])){$fenyenum=$_GET['p'];}else{$fenyenum=1;}	
		$fenye->config($zongji,10,$fenyenum,"0");		
		$record = $this->db->YPage("select * from `@#_yonghu_yys_record` where `uid`='$uid' and `huode`>'10000000' ORDER BY id DESC",array("num"=>10,"page"=>$fenyenum,"type"=>1,"cache"=>0));
		
		foreach($record as $ckey=>$cord){
			$jiexiao = huode_shop_if_jiexiao($cord['shopid']);
			if(!$jiexiao){
				unset($record[$ckey]);
			}
		}		
	
		include templates("mobile/member","orderDetail");
	}
	
public function orderDetails(){
		$huiyuan=$this->userinfo;	
		$crodid=intval($this->segment(4));
		$iii=$this->segment(4);
		$biaoti="订单详情";
		$records=$this->db->YOne("select * from `@#_yonghu_yys_record` where `id`='$crodid' and `uid`='$huiyuan[uid]' LIMIT 1");
		if($records['status']=='已付款,未发货,未完成,未提交地址'){
	$fhid = 0;
}elseif($records['status']=='已付款,未发货,未完成,已提交地址'){
	$fhid = 1;
}elseif($records['status']=='已付款,已发货,待收货'){
	$fhid = 2;
}elseif($records['status']=='已付款,已发货,已完成'){
	$fhid = 3;
}elseif($records['status']=='已付款,已发货,已作废'){
	$fhid = 4;
}
$status=@explode(",",$records['status']); 
$ii=$this->segment(4);
		$uid = $huiyuan['uid'];
		$biaoti="获得的商品 - "._yys("web_name");
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$biaoti="收货地址";
		$huiyuan_dizhi=$mysql_model->Ylist("select * from `@#_yonghu_dizhi` where uid='".$huiyuan['uid']."'  limit 1");
		$dizhi_sta=$this->db->YOne("select * from `@#_yonghu_yys_record` where id='$iii' limit 1");
		foreach($huiyuan_dizhi as $k=>$v){		
			$huiyuan_dizhi[$k] = _htmtguolv($v);
		}

		$count=count($huiyuan_dizhi);
		$zongji=$this->db->YCount("select * from `@#_yonghu_yys_record` where `uid`='$uid' and `huode`>'10000000'");
		$fenye=System::DOWN_sys_class('page');
		if(isset($_GET['p'])){$fenyenum=$_GET['p'];}else{$fenyenum=1;}	
		$fenye->config($zongji,10,$fenyenum,"0");		
		$record = $this->db->YPage("select * from `@#_yonghu_yys_record` where `uid`='$uid' and `huode`>'10000000' ORDER BY id DESC",array("num"=>10,"page"=>$fenyenum,"type"=>1,"cache"=>0));
		
		foreach($record as $ckey=>$cord){
			$jiexiao = huode_shop_if_jiexiao($cord['shopid']);
			if(!$jiexiao){
				unset($record[$ckey]);
			}
		}		
		
		include templates("mobile/member","orderDetails");
	}
	//fix by dabin

	public function orderDetailsb(){
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$uid=$huiyuan['uid'];
		$biaoti="订单详情";
		$iii=$this->segment(4);
$jj=isset($_POST['selectAddrID']) ? $_POST['selectAddrID'] : "";

//	var_dump();
	//exit;
	$huiyuan_dizhisss=$mysql_model->YOne("select * from `@#_yonghu_dizhi` where `id`='$jj'");
	//if($huiyuan_dizhisss);
	//exit;
$recordmmm=$mysql_model->YOne("select * from `@#_yonghu_yys_record` where `id`='$iii' and `uid`='$huiyuan[uid]' LIMIT 1");	
$recordmmmqq=$mysql_model->YOne("select * from `@#_shangpin` where `id`='$recordmmm[shopid]' LIMIT 1");
$rsrs1=$mysql_model->YOne("select * from `@#_configs` where `name`='web_key1'");
$rsrs2=$mysql_model->YOne("select * from `@#_configs` where `name`='web_key2'");		
//var_dump($records['shopqishu']);
		if(isset($_POST['btnSubmitCart'])){
			
	
			foreach($_POST as $k=>$v){
				$_POST[$k] = _htmtguolv($v);
			}
			
			$sheng111=isset($_POST['sheng']) ? $_POST['sheng'] : "";
		
			if(!empty($sheng111)){
			$sheng=isset($_POST['sheng']) ? $_POST['sheng'] : "";
			$shi=isset($_POST['shi']) ? $_POST['shi'] : "";
			$xian=isset($_POST['xian']) ? $_POST['xian'] : "";
			$jiedao=isset($_POST['jiedao']) ? $_POST['jiedao'] : "";
			$youbian=isset($_POST['youbian']) ? $_POST['youbian'] : "";
			$shouhuoren=isset($_POST['shouhuoren']) ? $_POST['shouhuoren'] : "";
			$tell=isset($_POST['tell']) ? $_POST['tell'] : "";
			$mobile=isset($_POST['mobile']) ? $_POST['mobile'] : "";
			$email=isset($_POST['email']) ? $_POST['email'] : "";
			
			

			
			}else{
				$sheng=$huiyuan_dizhisss['sheng'];
			$shi=$huiyuan_dizhisss['shi'];
			$xian=$huiyuan_dizhisss['xian'];
			$jiedao=$huiyuan_dizhisss['jiedao'];
			$youbian=$huiyuan_dizhisss['youbian'];
			$shouhuoren=$huiyuan_dizhisss['shouhuoren'];
			$tell=$huiyuan_dizhisss['tell'];
			$mobile=$huiyuan_dizhisss['mobile'];
			$email=$huiyuan_dizhisss['email'];
			
			

			
			}

			
             $qq=isset($_POST['qq']) ? $_POST['qq'] : "";
			
			$shipTime=isset($_POST['shipTime']) ? $_POST['shipTime'] : "";
			$shipRemark=isset($_POST['shipRemark']) ? $_POST['shipRemark'] : "";
			$kaka=isset($_POST['kaka']) ? $_POST['kaka'] : "";
			$time=time();
			
			if($kaka==1){
				if(empty($qq)){
				_notemobile("直冲类商品QQ不能为空",LOCAL_PATH."/mobile/home/orderlist",3);
				exit;
				}elseif (strlen($qq)<5||!is_numeric($qq)){
					_notemobile("QQ号码无效",LOCAL_PATH."/mobile/home/orderDetail/$recordmmm[id]",3);
					exit;
				}
				
				//QQ直冲
				//QQ冲值接口关闭
				$weerid = $rsrs1['value'];
$weerpws = strtolower(md5($rsrs2['value']));

//要充值的商品编号
$cardid = "220612";

//要充值的数量
$cardnum = $recordmmmqq['yuanjia'];

//外部订单号，唯一性
$sporder_id = $time;

//格式：年月日时分秒 如：20141209093450
$sporder_time = $time;

//game_userid=xxx@162.com$xxx001 xxx@162.com是通行证,xxx001是玩家账号
$game_userid = $qq;

//游戏玩家密码(可以为空)
$game_userpsw = "";

//区服没有则不写
$game_area = "";
$game_srv = "";

//该参数将异步返回充值结果，若不填写该地址，则不会回调
$ret_url = "http://xxxx";

//版本号固定值
$version = "6.0";


//默认的秘钥是OFCARD，可联系商务修改，若已经修改过的，请使用修改过的。
$keystr = "OFCARD";


$md5_str_param = $weerid.$weerpws.$cardid.$cardnum.$sporder_id.$sporder_time.$game_userid.$game_area.$game_srv.$keystr;
$md5_str = strtoupper(md5($md5_str_param));


if(!empty($game_area) or !empty($game_srv))
{
	//编码传输
	 $game_area = urlencode($game_area);
	 $game_srv = urlencode($game_srv);
	}


$url = "http://api2.ofpay.com/onlineorder.do?userid=".$weerid."&userpws=".$weerpws."&cardid=".$cardid."&cardnum=".$cardnum."&game_area=".$game_area."&game_srv=".$game_srv
."&sporder_id=".$sporder_id."&sporder_time=".$sporder_time."&game_userid=".$game_userid."&md5_str=".$md5_str."&version=".$version."&ret_url=".$ret_url;

//发送http请求
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
$contents = curl_exec($ch);
$res = simplexml_load_string($contents);  
$retcode = $res->retcode;
$err_msg = $res->err_msg;
if($retcode=="1"){
  $orderid = $res->orderid;
  $cardid = $res->cardid;
  $cardnum = $res->cardnum;
  $ordercash = $res->ordercash;
  $cardname = $res->cardname;
  $sporder_id = $res->sporder_id;
  $game_area = $res->game_area;
  $game_srv = $res->game_srv;
  $game_userid = $res->game_userid;
  $game_state = $res->game_state;
  
  
	}
	
			}

			//if($sheng==null or $jiedao==null or $shouhuoren==null or $mobile==null){
				//echo "带星号不能为空;";
				//exit;
			//}			
			//if(!_checkmobile($mobile)){
				//echo "手机号错误;";
				//exit;
			//}
			$huiyuan_dizhi=$mysql_model->YOne("select * from `@#_yonghu_dizhi` where `uid`='".$huiyuan['uid']."'");
			if(!$huiyuan_dizhi){
				$default="Y";
			}else{
				$default="N";
			}
			

	//	$mysql_model->Query("UPDATE `@#_yonghu_yys_record` SET shouhuo='1' where id='".$iii."'");
		
		
		$shopinfoss=$mysql_model->YOne("select * from `@#_shangpin` where `id`='$recordmmm[shopid]' LIMIT 1");
		
	//if(strpos($shopinfoss['title'],'Q')===false && strpos($shopinfoss['title'],'全国电信')===false && strpos($shopinfoss['title'],'全国移动')===false && strpos($shopinfoss['title'],'全国联通')===false)

	if($recordmmm['leixing']==0)
	{
		
		$status='已付款,未发货,未完成,已提交地址';
		
	}else{
		$status='已付款,已发货,已完成';
		
	}


		$mysql_model->Query("UPDATE `@#_yonghu_yys_record` SET shouhuo='1',status='$status',qq='$qq',youbian='$youbian',shipRemark='$shipRemark',shipTime='$shipTime',email='$email',tell='$tell',shouhuoren='$shouhuoren',mobile='$mobile',sheng='$sheng',shi='$shi',xian='$xian',jiedao='$jiedao',fhtime='$time',wei='0' where id='".$iii."'");
			$mysql_model->Query("INSERT INTO `@#_yonghu_dizhi`(`uid`,`sheng`,`shi`,`xian`,`jiedao`,`youbian`,`shouhuoren`,`tell`,`mobile`,`qq`,`default`,`time`)VALUES
			('$uid','$sheng','$shi','$xian','$jiedao','$youbian','$shouhuoren','$tell','$mobile','$qq','$default','$time')");
			
			_notemobile("添加成功",LOCAL_PATH."/mobile/home/orderDetail/$recordmmm[id]",3);
		}
	}



	//fix by dabin 微金币转换


public function excorderdetailsb(){
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$uid=$huiyuan['uid'];
		$biaoti="金币转换";
		$iii=$this->segment(4);
$jj=isset($_POST['selectAddrID']) ? $_POST['selectAddrID'] : "";

	$huiyuan_dizhisss=$mysql_model->YOne("select * from `@#_yonghu_dizhi` where `id`='$jj'");

$recordmmm=$mysql_model->YOne("select * from `@#_yonghu_yys_record` where `id`='$iii' and `uid`='$huiyuan[uid]' LIMIT 1");	
	
		if(isset($_POST['btnSubmitCart'])){
			foreach($_POST as $k=>$v){
				$_POST[$k] = _htmtguolv($v);
			}

			$kaka=isset($_POST['kaka']) ? $_POST['kaka'] : "";
			$time=time();
			
$shopinfoss=$mysql_model->YOne("select * from `@#_shangpin` where `id`='$recordmmm[shopid]' LIMIT 1");
if(empty($shopinfoss['yuanjia'])){
			_notemobile("未设置转换原价",LOCAL_PATH."/mobile/home/excorderdetail/$recordmmm[id]",3);
			exit;
		}
$bili = System::DOWN_App_config("user_fufen");

		
if($recordmmm['leixing']==0){
	  $jia=$shopinfoss['yuanjia']*$bili["fufen_yongjinqd0"];
      }else if ($recordmmm['leixing']==1){
		$jia=$shopinfoss['yuanjia']*$bili["fufen_yongjinqd1"];
	}else{
		$jia=$shopinfoss['yuanjia']*$bili["fufen_yongjinqd2"];
	}
	
			
	
		$pay_zhifu_name = '金币';
		if($recordmmm[wei]==1){
			_notemobile("您已经转换过哦",LOCAL_PATH."/mobile/home/excorderdetail/$recordmmm[id]",3);
			exit;
		}
		
		$mysql_model->Query("UPDATE `@#_yonghu` SET money1=money1+'".$jia."' where uid='".$huiyuan['uid']."'");
		$mysql_model->Query("UPDATE `@#_yonghu_yys_record` SET status='已付款,已发货,已完成',wei='1' where `id`='$iii' and `uid`='$huiyuan[uid]'");
		$mysql_model->Query("INSERT INTO `@#_yonghu_zhanghao1` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$uid', '-1', '$pay_zhifu_name', '商品id(".$shopinfoss['id'].")转换获得金币', '".$jia."', '$time')");	
			
			_notemobile("兑换成功",LOCAL_PATH."/mobile/home/orderlist",3);
		}
	}
	
//直购部分添加开始
	public function orderDetailzg(){
		$huiyuan=$this->userinfo;	
		$crodid=intval($this->segment(4));
		$iii=$this->segment(4);
		$biaoti="订单详情";
		if(is_numeric($iii)){
			$records=$this->db->YOne("select * from `@#_zg_yonghu_yys_record` where `id`='$crodid' and `uid`='$huiyuan[uid]' LIMIT 1");
			$tupian=$this->db->YOne("select * from `@#_zg_shangpin` where `id`='$records[shopid]' LIMIT 1");
			if($records['status']=='已付款,未发货,未完成,未提交地址'){
				$fhid = 0;
			}elseif($records['status']=='已付款,未发货,未完成,已提交地址'){
				$fhid = 1;
			}elseif($records['status']=='已付款,已发货,待收货'){
				$fhid = 2;
			}elseif($records['status']=='已付款,已发货,已完成'){
				$fhid = 3;
			}elseif($records['status']=='已付款,已发货,已作废'){
				$fhid = 4;
			}
			$status=@explode(",",$records['status']); 
			$ii=$this->segment(4);
			$uid = $huiyuan['uid'];
			$biaoti="购买的商品 - "._yys("web_name");
			$mysql_model=System::DOWN_sys_class('model');
			$huiyuan=$this->userinfo;
			$biaoti="收货地址";
			$huiyuan_dizhi=$mysql_model->Ylist("select * from `@#_yonghu_dizhi` where uid='".$huiyuan['uid']."'  limit 1");
			$dizhi_sta=$this->db->YOne("select * from `@#_zg_yonghu_yys_record` where id='$iii' limit 1");
			foreach($huiyuan_dizhi as $k=>$v){		
				$huiyuan_dizhi[$k] = _htmtguolv($v);
			}
			
			$count=count($huiyuan_dizhi);
			$zongji=$this->db->YCount("select * from `@#_zg_yonghu_yys_record` where `uid`='$uid' and `huode`>'10000000'");
			$fenye=System::DOWN_sys_class('page');
			if(isset($_GET['p'])){$fenyenum=$_GET['p'];}else{$fenyenum=1;}	
			$fenye->config($zongji,10,$fenyenum,"0");		
			$record = $this->db->YPage("select * from `@#_zg_yonghu_yys_record` where `uid`='$uid' and `huode`>'10000000' ORDER BY id DESC",array("num"=>10,"page"=>$fenyenum,"type"=>1,"cache"=>0));
			
			foreach($record as $ckey=>$cord){
				$jiexiao = huode_shop_if_jiexiao($cord['shopid']);
				if(!$jiexiao){
					unset($record[$ckey]);
				}
			}		
		}else{
			$addmoney_record = $this->db->YOne("select * from `@#_yonghu_addmoney_record` where `code` = '$iii'");
			$recordList = $this->db->YList("select * from `@#_zg_yonghu_yys_record` where `code`='$addmoney_record[orderCode]' and `uid`='$huiyuan[uid]'");
			foreach($recordList as $key => $records){
				$tupian=$this->db->YOne("select * from `@#_zg_shangpin` where `id`='$records[shopid]' LIMIT 1");
				if($records['status']=='已付款,未发货,未完成,未提交地址'){
					$fhid = 0;
				}elseif($records['status']=='已付款,未发货,未完成,已提交地址'){
					$fhid = 1;
				}elseif($records['status']=='已付款,已发货,待收货'){
					$fhid = 2;
				}elseif($records['status']=='已付款,已发货,已完成'){
					$fhid = 3;
				}elseif($records['status']=='已付款,已发货,已作废'){
					$fhid = 4;
				}
				$status=@explode(",",$records['status']); 
				$ii=$this->segment(4);
				$uid = $huiyuan['uid'];
				$biaoti="购买的商品 - "._yys("web_name");
				$mysql_model=System::DOWN_sys_class('model');
				$huiyuan=$this->userinfo;
				$biaoti="收货地址";
				$huiyuan_dizhi=$mysql_model->Ylist("select * from `@#_yonghu_dizhi` where uid='".$huiyuan['uid']."'  limit 1");
				$dizhi_sta=$this->db->YOne("select * from `@#_zg_yonghu_yys_record` where id='$records[id]' limit 1");

				foreach($huiyuan_dizhi as $k=>$v){		
					$huiyuan_dizhi[$k] = _htmtguolv($v);
				}
				
				$count=count($huiyuan_dizhi);
				$zongji=$this->db->YCount("select * from `@#_zg_yonghu_yys_record` where `uid`='$uid' and `huode`>'10000000'");
				$fenye=System::DOWN_sys_class('page');
				if(isset($_GET['p'])){$fenyenum=$_GET['p'];}else{$fenyenum=1;}	
				$fenye->config($zongji,10,$fenyenum,"0");		
				$record = $this->db->YPage("select * from `@#_zg_yonghu_yys_record` where `uid`='$uid' and `huode`>'10000000' ORDER BY id DESC",array("num"=>10,"page"=>$fenyenum,"type"=>1,"cache"=>0));
				
				foreach($record as $ckey=>$cord){
					$jiexiao = huode_shop_if_jiexiao($cord['shopid']);
					if(!$jiexiao){
						unset($record[$ckey]);
					}
				}
			}
		}
		include templates("mobile/member","orderDetailzg");
	}
	
public function orderDetailszg(){
		$huiyuan=$this->userinfo;	
		$crodid=intval($this->segment(4));
		$iii=$this->segment(4);
		$biaoti="订单详情";
		$records=$this->db->YOne("select * from `@#_zg_yonghu_yys_record` where `id`='$crodid' and `uid`='$huiyuan[uid]' LIMIT 1");
		if($records['status']=='已付款,未发货,未完成,未提交地址'){
	$fhid = 0;
}elseif($records['status']=='已付款,未发货,未完成,已提交地址'){
	$fhid = 1;
}elseif($records['status']=='已付款,已发货,待收货'){
	$fhid = 2;
}elseif($records['status']=='已付款,已发货,已完成'){
	$fhid = 3;
}elseif($records['status']=='已付款,已发货,已作废'){
	$fhid = 4;
}
$status=@explode(",",$records['status']); 
$ii=$this->segment(4);
		$uid = $huiyuan['uid'];
		$biaoti="购买的商品 - "._yys("web_name");
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$biaoti="收货地址";
		$huiyuan_dizhi=$mysql_model->Ylist("select * from `@#_yonghu_dizhi` where uid='".$huiyuan['uid']."'  limit 1");
		$dizhi_sta=$this->db->YOne("select * from `@#_zg_yonghu_yys_record` where id='$iii' limit 1");
		foreach($huiyuan_dizhi as $k=>$v){		
			$huiyuan_dizhi[$k] = _htmtguolv($v);
		}

		$count=count($huiyuan_dizhi);
		$zongji=$this->db->YCount("select * from `@#_zg_yonghu_yys_record` where `uid`='$uid' and `huode`>'10000000'");
		$fenye=System::DOWN_sys_class('page');
		if(isset($_GET['p'])){$fenyenum=$_GET['p'];}else{$fenyenum=1;}	
		$fenye->config($zongji,10,$fenyenum,"0");		
		$record = $this->db->YPage("select * from `@#_zg_yonghu_yys_record` where `uid`='$uid' and `huode`>'10000000' ORDER BY id DESC",array("num"=>10,"page"=>$fenyenum,"type"=>1,"cache"=>0));
		
		foreach($record as $ckey=>$cord){
			$jiexiao = huode_shop_if_jiexiao($cord['shopid']);
			if(!$jiexiao){
				unset($record[$ckey]);
			}
		}		
		
		include templates("mobile/member","orderDetailszg");
	}
	//fix by dabin

	public function orderDetailsbzg(){
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$uid=$huiyuan['uid'];
		
		$iii=$this->segment(4);
$jj=isset($_POST['selectAddrID']) ? $_POST['selectAddrID'] : "";

//	var_dump();
	//exit;
	$huiyuan_dizhisss=$mysql_model->YOne("select * from `@#_yonghu_dizhi` where `id`='$jj'");
	//if($huiyuan_dizhisss);
	//exit;
$recordmmm=$mysql_model->YOne("select * from `@#_zg_yonghu_yys_record` where `id`='$iii' and `uid`='$huiyuan[uid]' LIMIT 1");	
$recordmmmqq=$mysql_model->YOne("select * from `@#_zg_shangpin` where `id`='$recordmmm[shopid]' LIMIT 1");
$rsrs1=$mysql_model->YOne("select * from `@#_configs` where `name`='web_key1'");
$rsrs2=$mysql_model->YOne("select * from `@#_configs` where `name`='web_key2'");		
//var_dump($records['shopqishu']);
		if(isset($_POST['btnSubmitCart'])){
			
	
			foreach($_POST as $k=>$v){
				$_POST[$k] = _htmtguolv($v);
			}
			
			$sheng111=isset($_POST['sheng']) ? $_POST['sheng'] : "";
		
			if(!empty($sheng111)){
			$sheng=isset($_POST['sheng']) ? $_POST['sheng'] : "";
			$shi=isset($_POST['shi']) ? $_POST['shi'] : "";
			$xian=isset($_POST['xian']) ? $_POST['xian'] : "";
			$jiedao=isset($_POST['jiedao']) ? $_POST['jiedao'] : "";
			$youbian=isset($_POST['youbian']) ? $_POST['youbian'] : "";
			$shouhuoren=isset($_POST['shouhuoren']) ? $_POST['shouhuoren'] : "";
			$tell=isset($_POST['tell']) ? $_POST['tell'] : "";
			$mobile=isset($_POST['mobile']) ? $_POST['mobile'] : "";
			$email=isset($_POST['email']) ? $_POST['email'] : "";
			
			

			
			}else{
				$sheng=$huiyuan_dizhisss['sheng'];
			$shi=$huiyuan_dizhisss['shi'];
			$xian=$huiyuan_dizhisss['xian'];
			$jiedao=$huiyuan_dizhisss['jiedao'];
			$youbian=$huiyuan_dizhisss['youbian'];
			$shouhuoren=$huiyuan_dizhisss['shouhuoren'];
			$tell=$huiyuan_dizhisss['tell'];
			$mobile=$huiyuan_dizhisss['mobile'];
			$email=$huiyuan_dizhisss['email'];
			
			

			
			}

			
             $qq=isset($_POST['qq']) ? $_POST['qq'] : "";
			
			$shipTime=isset($_POST['shipTime']) ? $_POST['shipTime'] : "";
			$shipRemark=isset($_POST['shipRemark']) ? $_POST['shipRemark'] : "";
			$kaka=isset($_POST['kaka']) ? $_POST['kaka'] : "";
			$time=time();
			
			if($kaka==1){
				if(empty($qq)){
				_notemobile("直冲类商品QQ不能为空",LOCAL_PATH."/mobile/home/orderlistzg",3);
				exit;
				}elseif (strlen($qq)<5||!is_numeric($qq)){
					_notemobile("QQ号码无效",LOCAL_PATH."/mobile/home/orderDetailzg/$recordmmm[id]",3);
					exit;
				}
				
				//QQ直冲
				//QQ冲值接口关闭
				$weerid = $rsrs1['value'];
$weerpws = strtolower(md5($rsrs2['value']));

//要充值的商品编号
$cardid = "220612";

//要充值的数量
$cardnum = $recordmmmqq['yuanjia'];

//外部订单号，唯一性
$sporder_id = $time;

//格式：年月日时分秒 如：20141209093450
$sporder_time = $time;

//game_userid=xxx@162.com$xxx001 xxx@162.com是通行证,xxx001是玩家账号
$game_userid = $qq;

//游戏玩家密码(可以为空)
$game_userpsw = "";

//区服没有则不写
$game_area = "";
$game_srv = "";

//该参数将异步返回充值结果，若不填写该地址，则不会回调
$ret_url = "http://xxxx";

//版本号固定值
$version = "6.0";


//默认的秘钥是OFCARD，可联系商务修改，若已经修改过的，请使用修改过的。
$keystr = "OFCARD";


$md5_str_param = $weerid.$weerpws.$cardid.$cardnum.$sporder_id.$sporder_time.$game_userid.$game_area.$game_srv.$keystr;
$md5_str = strtoupper(md5($md5_str_param));


if(!empty($game_area) or !empty($game_srv))
{
	//编码传输
	 $game_area = urlencode($game_area);
	 $game_srv = urlencode($game_srv);
	}


$url = "http://api2.ofpay.com/onlineorder.do?userid=".$weerid."&userpws=".$weerpws."&cardid=".$cardid."&cardnum=".$cardnum."&game_area=".$game_area."&game_srv=".$game_srv
."&sporder_id=".$sporder_id."&sporder_time=".$sporder_time."&game_userid=".$game_userid."&md5_str=".$md5_str."&version=".$version."&ret_url=".$ret_url;

//发送http请求
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
$contents = curl_exec($ch);
$res = simplexml_load_string($contents);  
$retcode = $res->retcode;
$err_msg = $res->err_msg;
if($retcode=="1"){
  $orderid = $res->orderid;
  $cardid = $res->cardid;
  $cardnum = $res->cardnum;
  $ordercash = $res->ordercash;
  $cardname = $res->cardname;
  $sporder_id = $res->sporder_id;
  $game_area = $res->game_area;
  $game_srv = $res->game_srv;
  $game_userid = $res->game_userid;
  $game_state = $res->game_state;
  
  
	}
	
			}

			//if($sheng==null or $jiedao==null or $shouhuoren==null or $mobile==null){
				//echo "带星号不能为空;";
				//exit;
			//}			
			//if(!_checkmobile($mobile)){
				//echo "手机号错误;";
				//exit;
			//}
			$huiyuan_dizhi=$mysql_model->YOne("select * from `@#_yonghu_dizhi` where `uid`='".$huiyuan['uid']."'");
			if(!$huiyuan_dizhi){
				$default="Y";
			}else{
				$default="N";
			}
			

	//	$mysql_model->Query("UPDATE `@#_zg_yonghu_yys_record` SET shouhuo='1' where id='".$iii."'");
		
		
		$shopinfoss=$mysql_model->YOne("select * from `@#_zg_shangpin` where `id`='$recordmmm[shopid]' LIMIT 1");
		
	//if(strpos($shopinfoss['title'],'Q')===false && strpos($shopinfoss['title'],'全国电信')===false && strpos($shopinfoss['title'],'全国移动')===false && strpos($shopinfoss['title'],'全国联通')===false)

	if($recordmmm['leixing']==0)
	{
		
		$status='已付款,未发货,未完成,已提交地址';
		
	}else{
		$status='已付款,已发货,已完成';
		
	}


		$mysql_model->Query("UPDATE `@#_zg_yonghu_yys_record` SET shouhuo='1',status='$status',qq='$qq',youbian='$youbian',shipRemark='$shipRemark',shipTime='$shipTime',email='$email',tell='$tell',shouhuoren='$shouhuoren',mobile='$mobile',sheng='$sheng',shi='$shi',xian='$xian',jiedao='$jiedao',fhtime='$time',wei='0' where id='".$iii."'");
			$mysql_model->Query("INSERT INTO `@#_yonghu_dizhi`(`uid`,`sheng`,`shi`,`xian`,`jiedao`,`youbian`,`shouhuoren`,`tell`,`mobile`,`qq`,`default`,`time`)VALUES
			('$uid','$sheng','$shi','$xian','$jiedao','$youbian','$shouhuoren','$tell','$mobile','$qq','$default','$time')");
			
			_notemobile("添加成功",LOCAL_PATH."/mobile/home/orderDetailzg/$recordmmm[id]",3);
		}
	}



	//直购添加部分结束
//fix by dabin 微金币

	public function excorderdetail(){
		$huiyuan=$this->userinfo;	
		$crodid=intval($this->segment(4));
		$iii=$this->segment(4);
		$biaoti="订单转换金币";
		$records=$this->db->YOne("select * from `@#_yonghu_yys_record` where `id`='$crodid' and `uid`='$huiyuan[uid]' LIMIT 1");
		
		if($records['status']=='已付款,未发货,未完成,未提交地址'){
	$fhid = 0;
}elseif($records['status']=='已付款,未发货,未完成,已提交地址'){
	$fhid = 1;
}elseif($records['status']=='已付款,已发货,待收货'){
	$fhid = 2;
}elseif($records['status']=='已付款,已发货,已完成'){
	$fhid = 3;
}elseif($records['status']=='已付款,已发货,已作废'){
	$fhid = 4;
}
$status=@explode(",",$records['status']); 
$ii=$this->segment(4);
				
		
		include templates("mobile/member","excorderdetail");
	}


	//fix
	public function jifen(){
		$huiyuan=$this->userinfo;	
		$uid = $huiyuan['uid'];
		$biaoti="账户记录 - "._yys("web_name");		
		
		$zongji=$this->db->YCount("select * from `@#_yonghu_zhanghao1` where `uid`='$uid' and `pay` = '金币'");
		
		$fenye=System::DOWN_sys_class('page');
		if(isset($_GET['p'])){$fenyenum=$_GET['p'];}else{$fenyenum=1;}	
		$fenye->config($zongji,20,$fenyenum,"0");		
		$account = $this->db->YPage("select * from `@#_yonghu_zhanghao1` where `uid`='$uid' and `pay` = '金币' ORDER BY time DESC",array("num"=>20,"page"=>$fenyenum,"type"=>1,"cache"=>0));
		include templates("mobile/member","jifen");
	}
	public function zgreturn(){
		$huiyuan=$this->userinfo;	
		$uid = $huiyuan['uid'];
		$biaoti="直购返还 - "._yys("web_name");
		$wait = $this->db->YOne("select sum(`dayMoney`) as `countMoney` from `@#_zg_return_list` where `uid`='$uid' and `status` = '0'");
		$done = $this->db->YOne("select sum(`dayMoney`) as `countMoney` from `@#_zg_return_list` where `uid`='$uid' and `status` = '1'");
		$wait['countMoney'] = number_format($wait['countMoney'],2);
		$done['countMoney'] = number_format($done['countMoney'],2);
		include templates("mobile/member","zgreturn");
	}
	
	public function zgreturn1(){
		$huiyuan=$this->userinfo;	
		$uid = $huiyuan['uid'];
		$biaoti="直购返还 - "._yys("web_name");
		$wait = $this->db->YOne("select sum(`dayMoney`) as `countMoney` from `@#_zg_return_list` where `uid`='$uid' and `status` = '0'");
		$done = $this->db->YOne("select sum(`dayMoney`) as `countMoney` from `@#_zg_return_list` where `uid`='$uid' and `status` = '1'");
		$wait['countMoney'] = number_format($wait['countMoney'],2);
		$done['countMoney'] = number_format($done['countMoney'],2);
		include templates("mobile/member","zgreturn1");
	}
	
	public function jifenduihuan(){
		//$mysql_model=System::DOWN_sys_class('model');
		//$huiyuan=$this->userinfo;
		//$uid = $huiyuan['uid'];
		//$time=time();
		//$biaoti="充值到余额";
		
		//$amount=isset($_POST['amount']) ? $_POST['amount'] : "";

	
		$pay_zhifu_name = '金币';
		$mysql_model=System::DOWN_sys_class('model');
		$cashMoney = $mysql_model->YOne("select value from `@#_friend` where name='cashMoney'");
		$inviteCount = $mysql_model->YOne("select value from `@#_friend` where name='inviteCount'");
		$poundage = $mysql_model->YOne("select value from `@#_friend` where name = 'poundage'");
	
        $huiyuan=$this->userinfo;
        $uid = $huiyuan['uid'];
        $fmoney = $huiyuan['money1'];
        if(!$fmoney){
            $fmoney = 0;
        }
        if($fmoney >= 0){ //佣金提现金额限制可做修改。
            $cashouthdtotal = $fmoney;
        }else{
            $cashouthdtotal = 0;
        }
				

        if(isset($_POST['submit1'])){ //提现
			$money      = abs(intval($_POST['money']));
			$weername   =htmlspecialchars($_POST['txtUserName']);
			$bankname   =htmlspecialchars($_POST['txtBankName']);
			$branch     =htmlspecialchars($_POST['txtSubBank']);
			$banknumber =htmlspecialchars($_POST['txtBankNo']);
			$linkphone  =htmlspecialchars($_POST['txtPhone']);
			$time       =time();
			$cashType 	= 1;
			$type       = 1;  //佣金提现1/2余额转移
			$payType    = htmlspecialchars($_POST['payType']);
			$account	= htmlspecialchars($_POST['account']);
			$procefees  = $poundage['value'] / 100 * $money;
			
			$invite = $this->db->YOne("select count(*) as count from `@#_yonghu` where `yaoqing` = '$uid'");
			$result = $this->getAll();
			if($result['son1num'] < $inviteCount['value']){
				_notemobile("必须发展一级合伙人".$inviteCount['value']."人方可转到余额提现！");exit;
			}elseif($fmoney<$cashMoney['value']){
				_notemobile("佣金金额大于".$cashMoney['value']."元才能提现！");exit;
			}elseif($fmoney<$money ){
				_notemobile("输入额超出总佣金金额！");exit;
			}else{

				//插入提现申请表  这里不用在佣金表中插入记录 等后台审核才插入
				$this->db->Query("INSERT INTO `@#_yonghu_cashout1`(`procefees`,`cashType`,`uid`,`money`,`username`,`bankname`,`branch`,`banknumber`,`linkphone`,`time`,`payType`,`account`)VALUES
		('$procefees','$cashType','$uid','$money','$weername','$bankname','$branch','$banknumber','$linkphone','$time','$payType','$account')");
				$fmoney = $huiyuan['fmoney'] -$money;
				$this->db->Query("UPDATE `@#_yonghu` SET `money1`= `money1` - $money WHERE `uid`='$uid' ");
				_notemobile("申请成功！请等待审核！");
			}
        }
		

        if(isset($_POST['submit2'])){//充值
            $money      = abs(intval($_POST['amount']));
			$type       = 1;
			$pay        ="账户";
			$time       =time();
			$content    ="返佣金额转移到账户";

			if($money <= 0 || $money > $fmoney){
				_notemobile("佣金金额输入不正确！");exit;
			}
			$result = $this->getAll();
			if($result['son1num'] < $inviteCount['value']){
				_notemobile("必须发展一级合伙人".$inviteCount['value']."人方可转到余额提现！");exit;
			}
			if($money <= 0 || $money > $fmoney){
				_notemobile("佣金金额输入不正确！");exit;
			}
			if($money<$cashMoney['value']){
				_notemobile("佣金必须满".$cashMoney['value']."方可转到余额提现！");exit;
			}

			//插入记录
			$account=$this->db->Query("INSERT INTO `@#_yonghu_zhanghao`(`uid`,`type`,`pay`,`content`,`money`,`time`)VALUES
		('$uid','$type','$pay','$content','$money','$time')");

			// 查询是否有该记录
			if($account){
				//修改剩余金额
				$leavemoney=$huiyuan['money1'] - $money;
				$fmoney = $huiyuan['money'] + $money;
				$mrecode=$this->db->Query("UPDATE `@#_yonghu` SET `money1`='$leavemoney',`money`=$fmoney WHERE `uid`='$uid' ");
				//在佣金表中插入记录
				$recode=$this->db->Query("INSERT INTO `@#_fanyong_recodes`(`uid`,`type`,`content`,`money`,`time`)VALUES
		('$uid','-2','$content','$money','$time')");
				_notemobile("转移成功！");
			}else{
				_notemobile("转移失败！");
			}
        }

		/*if(isset($_POST['amount'])){
				//$amount='0.1';
				
			if (floor($amount)!=$amount) {
				_notemobile("不能是小数",LOCAL_PATH."/mobile/home/jifenduihuan",3);
				exit;
			} 
			if($amount>$huiyuan['money1']||$huiyuan['money1']<=0)
			{
				_notemobile("金币不足",LOCAL_PATH."/mobile/home/jifenduihuan",3);
				exit;
			}
			$mysql_model->Query("UPDATE `@#_yonghu` SET money1=money1-'".$amount."',money=money+'".$amount."' where uid='".$huiyuan['uid']."'");
			$mysql_model->Query("INSERT INTO `@#_yonghu_zhanghao1` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$uid', '-1', '$pay_zhifu_name', '金币转账到余额', '".$amount."', '$time')");	
					
			_notemobile("充值到余额成功",LOCAL_PATH."/mobile/home/jifenduihuan",3);
		}*/
		include templates("mobile/member","jifenduihuan");
	}
	
	
	public function withdrawRecord(){
	
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$uid = $huiyuan['uid'];
		$recount=0;
		$fufen = System::DOWN_app_config("user_fufen",'','member');
		//查询提现记录	 
		//$recordarr=$mysql_model->Ylist("select * from `@#_yonghu_recodes` a left join `@#_yonghu_cashout` b on a.cashoutid=b.id where a.`uid`='$uid' and a.`type`='-3' ORDER BY a.`time` DESC");		$recordarr=
		
		$jfwitem=$mysql_model->Ylist("select * from  `@#_yonghu_cashout1`  where `uid`='$uid' ORDER BY `time` DESC limit 0,30");
        
		if(!empty($recordarr)){
		  $recount=1;
		}		
		include templates("mobile/member","withdrawRecord");
	}

	//
//fix by dabin 签到
	public function signpop(){
		
		
		include templates("member","signpop");
	}

    // by xfx
    public function userzzfb_menu(){
        $biaoti="供应商(众筹)";
        $huiyuan = $this->userinfo;
		$guanggao8=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '8'");
		$gyszg = System::DOWN_App_config("user_gyszg","","admin");	
		$zzfb =  $this->db->YOne("SELECT * from `@#_yonghu_zzzg` where `uid` = '$huiyuan[uid]'");
		if($zzfb['gyszg'] > $huiyuan['score'] && $zzfb['stuats'] != 2){
			_notemobile("尚未获得申请资格，如有需要请先联系管理员！");
		}
		
        include templates("mobile/user","userzzfb_menu");
    }
    public function friend_menu(){
        $biaoti="合伙人菜单";
        $huiyuan = $this->userinfo;
		$guanggao9=$this->db->YOne("select * from `@#_guanggao_shuju` where `id` = '9'");
        include templates("mobile/user","friend_menu");
    }
    public function start_menu(){
        $biaoti="星级老板菜单";
        $huiyuan = $this->userinfo;
        include templates("mobile/user","start_menu");
    }


    //供应商资格自助申请
    public function userzzzg(){
	
		$huiyuan=$this->userinfo;
		$zzfb =  $this->db->YOne("SELECT * from `@#_yonghu_zzzg` where `uid` = '$huiyuan[uid]'");
		$gyszg = System::DOWN_App_config("user_gyszg","","admin");	

		if($gyszg['gyszg'] > $huiyuan['score'] || ($gyszg['gyszg'] > $huiyuan['score'] && $zzfb['stuats'] != 2)){
			_notemobile("您需福分达到".$gyszg['gyszg']."以后才具备申请资格，请先赚福分或联系管理员开通！",LOCAL_PATH."/mobile/mobile/zzfb/35.html",3);
		}
		$gradeConfig = System::DOWN_App_config("user_gyszg","","admin");
		unset($gradeConfig['gyszg']);
		unset($gradeConfig['bzj']);
		$gradeList = array(
			'normal' => array(
				'normalGoodsNum' => $gradeConfig['normalGoodsNum'],
				'normalServiceTime' => $gradeConfig['normalServiceTime'],
				'normalFirstMoney' => $gradeConfig['normalFirstMoney'],
				'normalFirstRenewalMoney' => $gradeConfig['normalFirstRenewalMoney'],
				'description' => '普通供应商',
				'ServiceTime' => $gradeConfig['normalServiceTime'],
				'FirstMoney' => $gradeConfig['normalFirstMoney'],
				'FirstRenewalMoney' => $gradeConfig['normalFirstRenewalMoney'],
				'tips' => '普通供应商，可提交商品件数：'.$gradeConfig['normalGoodsNum'].'件；<br/>服务时间：'.$gradeConfig['normalServiceTime'].'年，首次开通费用：'.$gradeConfig['normalFirstMoney'].'元，续费（每年）：'.$gradeConfig['normalFirstRenewalMoney'].'元<br/>',
			),
			'gold' => array(
				'goldGoodsNum' => $gradeConfig['goldGoodsNum'],
				'goldServiceTime' => $gradeConfig['goldServiceTime'],
				'goldFirstMoney' => $gradeConfig['goldFirstMoney'],
				'goldFirstRenewalMoney' => $gradeConfig['goldFirstRenewalMoney'],
				'description' => '金牌供应商',
				'ServiceTime' => $gradeConfig['goldServiceTime'],
				'FirstMoney' => $gradeConfig['goldFirstMoney'],
				'FirstRenewalMoney' => $gradeConfig['goldFirstRenewalMoney'],
				'tips' => '金牌供应商，可提交商品件数：'.$gradeConfig['goldGoodsNum'].'件，<br/>服务时间：'.$gradeConfig['goldServiceTime'].'年，首次开通费用：'.$gradeConfig['goldFirstMoney'].'元，续费（每年）：'.$gradeConfig['goldFirstRenewalMoney'].'元<br/>',
			),
			'platinum' => array(
				'platinumGoodsNum' => $gradeConfig['platinumGoodsNum'],
				'platinumServiceTime' => $gradeConfig['platinumServiceTime'],
				'platinumFirstMoney' => $gradeConfig['platinumFirstMoney'],
				'platinumFirstRenewalMoney' => $gradeConfig['platinumFirstRenewalMoney'],
				'description' => '白金供应商',
				'ServiceTime' => $gradeConfig['platinumServiceTime'],
				'FirstMoney' => $gradeConfig['platinumFirstMoney'],
				'FirstRenewalMoney' => $gradeConfig['platinumFirstRenewalMoney'],
				'tips' => '白金供应商，可提交商品件数：'.$gradeConfig['platinumGoodsNum'].'件,<br/>服务时间：'.$gradeConfig['platinumServiceTime'].'年，首次开通费用：'.$gradeConfig['platinumFirstMoney'].'元，续费（每年）：'.$gradeConfig['platinumFirstRenewalMoney'].'元<br/>',
			),
		);
		
		$tips = $gradeList[$zzfb['supplyGrade']]['tips'];
	
		if($zzfb['supplyGradeTime']){
			$gradeTime = date('Y-m-d H:i:s',$zzfb['supplyGradeTime']);
		}
		

		$needMoney = $gradeList[$zzfb['supplyGrade']][$zzfb['supplyGrade'].'FirstRenewalMoney'];
		$goodYear = $gradeList[$zzfb['supplyGrade']][$zzfb['supplyGrade'].'ServiceTime'];
		

		if($zzfb['supplyGrade'] == 'normal' || $zzfb['supplyGrade'] == 'gold' || $zzfb['supplyGrade'] == 'platinum'){
			unset($gradeList['normal']);
		}
		
		if($zzfb['supplyGrade'] == 'gold' || $zzfb['supplyGrade'] == 'platinum'){
			unset($gradeList['gold']);
		}
		if($zzfb['supplyGrade'] == 'platinum'){
			unset($gradeList['platinum']);
		}
		
        $uid = $huiyuan['uid'];
        $mysql_model=System::DOWN_sys_class('model');
        if(isset($_POST['submit'])){
			$supplyGrade = trim($_POST['supplyGrade']);
            $name=_htmtguolv(trim($_POST['name']));
            $name = str_ireplace("'","",$name);
            $type=(trim($_POST['type']));
            $tel=_htmtguolv(trim($_POST['tel']));
            $card=_htmtguolv(trim($_POST['card']));
            $address=_htmtguolv(trim($_POST['address']));
            $checktype=_htmtguolv(trim($_POST['checktype']));
            $checknum=_htmtguolv(trim($_POST['checknum']));
            $bak=_htmtguolv(trim($_POST['bak']));
            $time = time();

			$gradeConfig = System::DOWN_App_config("user_gyszg","","admin");
			$supplyGradeTime = time() + $gradeConfig[$supplyGrade.'ServiceTime'] * 3600 * 24 * 365;
            $mysql_model->Query("INSERT INTO `@#_yonghu_zzzg` (`supplyGrade`,`supplyGradeTime`,`uid`,`type`,`name`,`tel`,`card`,`address`,`checktype`,`checknum`,`bak`,`stuats`,`add_time`) values ('$supplyGrade','$supplyGradeTime','$uid',$type,'$name','$tel','$card','$address','$checktype','$checknum','$bak','',$time)");
            _notemobile("资料提交成功，请等待审核！");

        }else {
            $this->zzfb = $mysql_model->YOne("SELECT * from `@#_yonghu_zzzg` where `uid` = '$uid'");
            $zzfb = $this->zzfb;
			if($zzfb['supplyGrade'] == 'normal'){
				$grade = '普通供应商';
			}elseif($zzfb['supplyGrade'] == 'gold'){
				$grade = '金牌供应商';
			}elseif($zzfb['supplyGrade'] == 'platinum'){
				$grade = '白金供应商';
			}
        }

        $biaoti="供应商(众筹)申请";
        include templates("mobile/user","userzzzg");
    }

    public function userzzlist(){


        $biaoti="供应商(众筹)商品列表";
        include templates("mobile/user","zzfblist");
    }

    public function userzzadd(){
        $huiyuan=$this->userinfo;
        $uid = $huiyuan['uid'];
        $mysql_model=System::DOWN_sys_class('model');
		$biaoti="用户添加商品";
        if(isset($_POST['submit'])){

            $biaoti = _htmtguolv($_POST['title']);
            $miaoshu = htmlspecialchars($_POST['description']);

            $content = $this->editor_safe_replace(stripslashes($_POST['content']));

            $money = intval($_POST['money']);
            $yongjin = intval($_POST['yongjin']);
            $thumb = htmlspecialchars($_POST['thumb']);

            if($_FILES['thumb']['error'] > 0){
                _notemobile("上传图片出错,或未传商品图片");
            }
            if($_FILES['thumb']['size'] > 1000000){
                _notemobile("文件太大");
            }
            if($_FILES['thumb']['type']!='image/jpeg' && $_FILES['thumb']['type']!='image/gif' && $_FILES['thumb']['type']!='image/jpg' && $_FILES['thumb']['type']!='image/bmp' && $_FILES['thumb']['type']!='image/png'){
                _notemobile("图片格式不对");
            }
            $today = date("YmdHis");
            $filetype = $_FILES['thumb']['type'];
            if($filetype == 'image/jpeg'){
                $type = '.jpg';
            }
            if($filetype == 'image/jpg'){
                $type = '.jpg';
            }
            if($filetype == 'image/gif'){
                $type = '.gif';
            }
            if($filetype == 'image/png'){
                $type = '.png';
            }
            if($filetype == 'image/bmp'){
                $type = '.bmp';
            }
            $upfile = 'statics/uploads/image/' . $today . $type;
            if(is_uploaded_file($_FILES['thumb']['tmp_name']))
            {
                if(!move_uploaded_file($_FILES['thumb']['tmp_name'], $upfile))
                {
                    _notemobile("上传文件失败");
                }
            }
            $upfile = 'image/' . $today . $type;

            $maxqishu = intval($_POST['maxqishu']);
            $remote_url = $_POST['remote_url'];

            if(!$biaoti)_notemobile("标题不能为空");
            if(!$money)_notemobile("价格不能为空");
            if(!$yongjin)_notemobile("佣金不能为空");
//            if(!$remote_url) {
 //               if (!$thumb) _notemobile("未上传远程地址，所以缩略图不能为空");
//            }

            if($_POST['xsjx_time'] != ''){
                $xsjx_time = strtotime($_POST['xsjx_time']) ? strtotime($_POST['xsjx_time']) : time();
                $xsjx_time_h = intval($_POST['xsjx_time_h']) ? $_POST['xsjx_time_h'] : 36000;
                $xsjx_time += $xsjx_time_h;
            }else{
                $xsjx_time = '0';
            }
			
            if($maxqishu > 65535){
                _notemobile("最大期数不能超过65535期");
            }
            $time=time();	//添加时间
            $mysql_model->tijiao_start();

            $query_1 = $mysql_model->Query("INSERT INTO `@#_sqfb` (`title`, `description`, `money`, `yongjin`, `maxqishu`,`thumb`, `content`,`xsjx_time`,`time`,`uid`,remote_url ) VALUES ( '$biaoti', '$miaoshu', '$money', '$yongjin', '$maxqishu', '$upfile', '$content','$xsjx_time','$time',$uid,'$remote_url')");

            if($query_1){
                $mysql_model->tijiao_commit();
                _notemobile("资料提交成功，请等待审核通知！",LOCAL_PATH."/mobile/home/userzzlist",3);
            }else{

                $mysql_model->tijiao_rollback();
                _notemobile("申请失败，请重试或联系管理员！",LOCAL_PATH."/mobile/home/userzzfb_menu",3);
            }
        }
        else {
            $this->zzfb = $mysql_model->YOne("SELECT * from `@#_yonghu_zzzg` where `uid` = '$uid'");
            $zzfb = $this->zzfb;
            $biaoti="供应商(众筹)商品发布";
            include templates("mobile/user","userzzadd");
        }

    }

    public function getzzfb(){
        $id=intval($this->segment(4));
        $huiyuan=$this->userinfo;
        $uid = $huiyuan['uid'];
        $mysql_model=System::DOWN_sys_class('model');
		$biaoti="商品发布";


        $zzList = $mysql_model->YOne("SELECT * from `@#_sqfb` where `uid` = '$uid' and id=$id");
        if(!$zzList){
            _notemobile("非法参数",LOCAL_PATH."/mobile/home",3);
        }else{
            if($zzList['stuats'] != 2){
                _notemobile("尚未通过审核",LOCAL_PATH."/mobile/home/userzzlist",3);
            }
            else if($zzList['goods_id'] == 0){
                _notemobile("后台尚未发布商品，请耐心等待",LOCAL_PATH."/mobile/home/userzzlist",3);
            }else{
                $goods = $mysql_model->YOne("SELECT * from `@#_shangpin` where  id=".$zzList['goods_id'] );
                $tpath =  $_SERVER['SERVER_NAME'];

                /*require_once("yungousys/class/mobile/jssdk.php");
                $yaoqing = System::DOWN_App_config("user_fufen");


                $appid = $yaoqing[appid];
                $secret = $yaoqing[secret];
                $jssdk = new JSSDK($appid, $secret);
                $signPackage = $jssdk->GetSignPackage();*/
            }

        }
        include templates("mobile/user","usergetzzfb");
    }


    public function friend(){
        include templates("member","friend");
    }
    public function friend_add(){

        $huiyuan=$this->userinfo;
        $uid = $huiyuan['uid'];
        $mysql_model=System::DOWN_sys_class('model');
        $id =intval($this->segment(4));
        $friend = $huiyuan['friend'];
        if($id){
            if($friend){
                _notemobile("申请失败，您已拥有合伙人套餐了");
            }else {
                $time=time();
                $taocan = $mysql_model->YOne("SELECT * from `@#_fanyong_taocan` where `id` = $id");

                if($huiyuan['fid'] != 0) {
                    $ftaocan = $mysql_model->YOne("SELECT * from `@#_fanyong` where `uid` = $huiyuan[fid]");
//修复合伙人中间中断下级不能成为合伙人的问题20160804
					if(!$ftaocan['taocan_id']){
						$ftaocan['taocan_id'] = $id;
					}
                    $ftaocan = $mysql_model->YOne("SELECT * from `@#_fanyong_taocan` where `id` = $ftaocan[taocan_id]");
                    if ($ftaocan['price'] > $taocan['price']) {
                        _notemobile("申请失败，申请套餐不得低于上级会员所拥有的套餐，上级会员套餐价值" . $ftaocan['price'] . '元');
                    } else {

                        if ($huiyuan['money'] >= $taocan['price']) {
                            $mysql_model->Query("INSERT INTO `@#_fanyong` (`uid`,`taocan_id`,`add_time`) values ('$uid',$id,$time)");
                            $huiyuan['money'] -= $taocan['price'];
                            $mysql_model->Query("UPDATE `@#_yonghu` set money = $huiyuan[money] where uid =$uid");
                            $recode = $this->db->Query("INSERT INTO `@#_fanyong_recodes`(`uid`,`type`,`content`,`money`,`time`)VALUES
			('$uid','10','购买$taocan[name]','$taocan[price]','$time')");

//写入到会员消费表
			$this->db->Query("INSERT INTO `@#_yonghu_zhanghao`(`uid`,`type`,`pay`,`content`,`money`,`time`)VALUES
			('$uid','-1','账户','购买$taocan[name]','$taocan[price]','$time')");
                            _notemobile("申请成功");
                        } else {
                            _notemobile("申请失败，余额低于" . $taocan['price'] . '元');
                        }
                    }
                }
                else{
                    if ($huiyuan['money'] >= $taocan['price']) {
                        $mysql_model->Query("INSERT INTO `@#_fanyong` (`uid`,`taocan_id`,`add_time`) values ('$uid',$id,$time)");
                        $huiyuan['money'] -= $taocan['price'];
                        $mysql_model->Query("UPDATE `@#_yonghu` set money = $huiyuan[money] where uid =$uid");
                        $this->db->Query("INSERT INTO `@#_fanyong_recodes`(`uid`,`type`,`content`,`money`,`time`)VALUES
			('$uid','10','购买$taocan[name]',$taocan[price],'$time')");

                        $this->db->Query("INSERT INTO `@#_yonghu_zhanghao`(`uid`,`type`,`pay`,`content`,`money`,`time`)VALUES
			('$uid','-1','账户','购买$taocan[name]','$taocan[price]','$time')");	
                            _notemobile("祝贺您，您已成功申请合伙人");
                    } else {
                        _notemobile("申请失败，请先充值，当前余额低于" . $taocan['price'] . '元');
                    }
                }

            }

        }else {

            $list = $this->db->YList("select * from `@#_fanyong_taocan`");
        }

        $biaoti="合伙人申请";

        include templates("mobile/user","friend_add");
    }
    public function friend_list_info(){



        $result = $this->getAll();


        $biaoti="合伙人明细 - "._yys("web_name");

        include templates("mobile/user","friend_list_info");
    }
    public function friend_list(){
        $mysql_model=System::DOWN_sys_class('model');
        $huiyuan=$this->userinfo;



        $result = $this->getAll();



        $biaoti="合伙人管理 - "._yys("web_name");

        $summoney = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' ");
        $summoney = $summoney['price'];

        $zongji=$this->db->YCount("select * from `@#_fanyong_list` where `uid`='$huiyuan[uid]' ");
        $fenye=System::DOWN_sys_class('page');
        if(isset($_GET['p'])){$fenyenum=$_GET['p'];}else{$fenyenum=1;}
        $fenye->config($zongji,10,$fenyenum,"0");
        $list = $this->db->YPage("select * from `@#_fanyong_list` where `uid`='$huiyuan[uid]'  ORDER BY id DESC",array("num"=>10,"page"=>$fenyenum,"type"=>1,"cache"=>0));
        foreach($list as $v => $k){
            $user=$mysql_model->YOne("select email,mobile from `@#_yonghu` where `uid`='$k[fanyong_id]' ");
            if($user['mobile']){
                $list[$v]['name'] = $user['mobile'];
            }else{
                $list[$v]['name'] = $user['email'];
            }
            $ucount = $mysql_model->YOne("select COUNT(*) as count from `@#_fanyong_list` where `fanyong_id`='$k[fanyong_id]' and uid = $huiyuan[uid]");
            $list[$v]['count'] = $ucount['count'];
            foreach($result['alluser'] as $a){

                if($a['user']['uid'] == $k[fanyong_id]){

                    $list[$v]['level'] = $a['level'];
                }
            }
        }
        $listcount = count($list);


        include templates("mobile/user","friend_list");
    }

    // 一键领取
    function get_today(){
        $mysql_model=System::DOWN_sys_class('model');
        $huiyuan=$this->userinfo;
        $muid = $huiyuan['uid'];
        $result = $this->getAll();
        $day = $this->day['value'];
        $off = $this->off['value'];

        $stuats = $mysql_model->YOne("select * from `@#_fanyong` where  uid = $muid");
        if(!$stuats){
            _notemobile("请先申请成为合伙人，每天可领取佣金");
        }
        if($stuats['stuats'] == 0){
            _notemobile("Sorry，您的资格已被停用请联系管理员");
        }
        if($off == 1){
            $alluser = $result['alluser'];
            $allmoney = 0;
            if(empty($alluser)){
				_notemobile("领取失败，一天只能领取一次哦！快去发展下线吧！");
            }
            foreach($alluser as $a){
                $i = 0;
                $uid = $a['user']['uid'];
                $fanyong = $mysql_model->YList("select * from `@#_fanyong_list` where `fanyong_id`=$uid and uid = $muid  order by fanyong_time desc");
				$tancanId = $mysql_model->YOne("select * from `@#_fanyong_taocan` where `id` = '$stuats[taocan_id]'");
				$day = $tancanId['evenlopeDay'];
				
                //判断是否已经超过总次数
                if(count($fanyong) < $day){
                    if(count($fanyong) > 0){
                        $new = current($fanyong);

                        //判断是否为今天
                        if(date('Y-m-d') != date('Y-m-d',$new['fanyong_time'])){
                            $taocan = $mysql_model->YOne("select t.*,f.add_time as begin_time from `@#_fanyong_taocan` as t left JOIN `@#_fanyong` as f ON t.id = f.taocan_id where uid = $uid and f.stuats = 1");

                            //判断下级用户购买套餐日期到今日是否已经超过有效期
                            if($taocan['begin_time']){

                                if(intval((time() - $taocan['begin_time']) / 3600*24) <= $day*2*3600*24){

                                    $level ="";
                                    //判断用户级别
                                    switch($a['level']){
                                        case 1:
                                            $level = 'son1';
                                            break;
                                        case 2:
                                            $level = 'son2';
                                            break;
                                        case 3:
                                            $level = 'son3';
                                            break;
                                        case 4:
                                            $level = 'son4';
                                            break;
                                        case 5:
                                            $level = 'son5';
                                            break;
                                        case 6:
                                            $level = 'son6';
                                            break;
                                    }
                                    $now_time = time();
									/*修改套餐返还金额*/
									$taocan[$level] = $tancanId[$level];
                                    $this->db->Query("INSERT INTO `@#_fanyong_list`(`uid`,`fanyong_id`,`price`,`fanyong_time`)VALUES ('$muid','$uid','$taocan[$level]',$now_time)");
                                    $allmoney += $taocan[$level];
                                }
                            }
                        }
                    }else{

                        $taocan = $mysql_model->YOne("select t.*,f.add_time as begin_time from `@#_fanyong_taocan` as t left JOIN `@#_fanyong` as f ON t.id = f.taocan_id where uid = $uid and f.stuats = 1");

                        //判断下级用户购买套餐日期到今日是否已经超过有效期
                        if($taocan['begin_time']){

                            if(intval((time() - $taocan['begin_time']) / 3600*24) <= $day*2*3600*24){
                                $level ="";
                                //判断用户级别
                                switch($a['level']){
                                    case 1:
                                        $level = 'son1';
                                        break;
                                    case 2:
                                        $level = 'son2';
                                        break;
                                    case 3:
                                        $level = 'son3';
                                        break;
                                    case 4:
                                        $level = 'son4';
                                        break;
                                    case 5:
                                        $level = 'son5';
                                        break;
                                    case 6:
                                        $level = 'son6';
                                        break;
                                }
								
								/*修改套餐返还金额*/
								$taocan[$level] = $tancanId[$level];
                                $now_time = time();
                                $this->db->Query("INSERT INTO `@#_fanyong_list`(`uid`,`fanyong_id`,`price`,`fanyong_time`)VALUES ('$muid','$uid','$taocan[$level]',$now_time)");
                                $allmoney += $taocan[$level];

                            }
                        }
                    }
                }
            }
            $temp =$allmoney + $huiyuan['fmoney'];
            $this->db->Query("UPDATE `@#_yonghu` SET `fmoney`=$temp WHERE `uid`='$muid' ");
            _notemobile("领取成功,共领取返佣".$allmoney."元,一天只能领取一次哦！");
        }else{
            _notemobile("领取失败，活动结束，系统已停止返佣");
        }


    }

    /**
     * @return  $result['alluser'] = $alluser;
    $result['son1price'] = $son1price;
    $result['son2price'] = $son2price;
    $result['son3price'] = $son3price;
    $result['son4price'] = $son4price;
    $result['son5price'] = $son5price;
    $result['son6price'] = $son6price;

    $result['son1_list'] = $son1_list;
    $result['son2_list'] = $son2_list;
    $result['son3_list'] = $son3_list;
    $result['son4_list'] = $son4_list;
    $result['son5_list'] = $son5_list;
    $result['son6_list'] = $son6_list;

    $result['son1num'] = $son1num;
    $result['son2num'] = $son2num;
    $result['son3num'] = $son3num;
    $result['son4num'] = $son4num;
    $result['son5num'] = $son5num;
    $result['son6num'] = $son6num;
    $result['totalnum'] = $totalnum;
     */


    //返佣排行榜 thisweek前30名
    function friend_top(){


        $date=new DateTime();
        $date->modify('this week');

      //  $first_day_of_week=$date->format('Y-m-d 00:00:00');
        $date->modify('this week +6 days');
        $end_day_of_week=$date->format('Y-m-d 23:59:59');
        $startWeek = strtotime( date("Y-m-d",strtotime("-1 day")));
        $endWeek = $startWeek - 7*24*7200;
        $sqlWeek = "select DISTINCT SUM(f.price) as money, f.uid,y.username as username1 from yys_fanyong_list as f right join yys_yonghu as y on y.uid = f.uid and f.fanyong_time between ".$endWeek." and ".$startWeek." group by y.uid order by money desc limit 0,30";
        $listWeek = $this->db->Ylist($sqlWeek);

        $strWeek = "<li class='in_progress'  style='text-align: center'><table  style='text-align: center'><thead  style='text-align: center'>";
        foreach($listWeek as $key => $val){

            if($val['money'] != "") {
                $noname = '尚未设置昵称';
                $strWeek .= '<tr class="odd">';
                $strWeek .= '<td><span>' . ($key + 1) . '</span></td>';
                $strWeek .= '<td><span><a style="color:blue;text-decoration: underline;" href="' . LOCAL_PATH . '/uname/' . $val['uid'] . '" target="_blank">' . ($val['username1'] ? $val['username1'] : $noname) . '</a></span></td>';
                $strWeek .= '<td><span>' . $val['money'] . '</span></td>';
                $strWeek .= '</tr>';
            }
        }

        $strWeek .= "</thead></table></li>";
        include templates("mobile/user","friend_top");
    }


    function getAll($type=0){
        //查询返佣信息
        $key = 0;
        $alluser = array();
        $result = array();
        $mysql_model=System::DOWN_sys_class('model');
        $huiyuan=$this->userinfo;
        $son1=$mysql_model->Ylist("select * from `@#_yonghu` as y left join `@#_fanyong` as f on y.uid = f.uid  where  f.stuats = 1  and y.fid ='$huiyuan[uid]'");
        $son1num = count($son1);
        $son2num = 0;
        $son3num = 0;
        $son4num = 0;
        $son5num = 0;
        $son6num = 0;

        $son1price = $son2price = $son3price = $son4price = $son5price = $son6price = 0;

        $son1_list = $son2_list = $son3_list = $son4_list =$son5_list =$son6_list = "";

        foreach ($son1 as $s1) {
            if ($s1['mobile']) {
                $son1_list .= '<a href='.LOCAL_PATH."/uname/".$s1[uid].".html >".$s1['mobile'] . "</a>,";
            } else {
                $son1_list .= '<a href='.LOCAL_PATH."/uname/".$s1[uid].".html  >".$s1['email'] . "</a>,";
            }
            $alluser[$key]['user'] = $s1;
            $alluser[$key]['level'] = 1;
            $key++;
            $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `type` = '$type' and `uid`='$huiyuan[uid]' and `fanyong_id` = $s1[uid]");
            $son1price += $temp['price'];

            $son2 = $mysql_model->Ylist("select * from `@#_yonghu` as y left join `@#_fanyong` as f on y.uid = f.uid  where  f.stuats = 1  and y.fid ='$s1[uid]'");
            $son2num += count($son2);
            foreach ($son2 as $s2) {
                if ($s2['mobile']) {
                    $son2_list .= '<a href='.LOCAL_PATH."/uname/".$s2[uid].".html >".$s2['mobile'] . "</a>,";
                } else {
                    $son2_list .= '<a href='.LOCAL_PATH."/uname/".$s2[uid].".html  >".$s2['email'] . "</a>,";
                }
                $alluser[$key]['user'] = $s2;
                $alluser[$key]['level'] = 2;
                $key++;
                $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `type` = '$type' and `uid`='$huiyuan[uid]' and `fanyong_id` = $s2[uid]");
                $son2price += $temp['price'];

                $son3 = $mysql_model->Ylist("select * from `@#_yonghu`  as y left join `@#_fanyong` as f on y.uid = f.uid  where  f.stuats = 1  and y.fid ='$s2[uid]' ");
                $son3num += count($son3);
                foreach ($son3 as $s3) {
                    if ($s3['mobile']) {
                        $son3_list .= '<a href='.LOCAL_PATH."/uname/".$s3[uid].".html  >".$s3['mobile'] . "</a>,";
                    } else {
                        $son3_list .= '<a href='.LOCAL_PATH."/uname/".$s3[uid].".html  >".$s3['email'] . "</a>,";
                    }
                    $alluser[$key]['user'] = $s3;
                    $alluser[$key]['level'] = 3;
                    $key++;
                    $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `type` = '$type' and `uid`='$huiyuan[uid]' and `fanyong_id` = $s3[uid]");
                    $son3price += $temp['price'];

                    $son4 = $mysql_model->Ylist("select * from `@#_yonghu` as y left join `@#_fanyong` as f on y.uid = f.uid  where  f.stuats = 1  and y.fid ='$s3[uid]' ");
                    $son4num += count($son4);
                    foreach ($son4 as $s4) {
                        if ($s4['mobile']) {
                            $son4_list .= '<a href='.LOCAL_PATH."/uname/".$s4[uid].".html >".$s4['mobile'] . "</a>,";
                        } else {
                            $son4_list .= '<a href='.LOCAL_PATH."/uname/".$s4[uid].".html >".$s4['email'] . "</a>,";
                        }
                        $alluser[$key]['user'] = $s4;
                        $alluser[$key]['level'] = 4;
                        $key++;
                        $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `type` = '$type' and `uid`='$huiyuan[uid]' and `fanyong_id` = $s4[uid]");
                        $son4price += $temp['price'];

                        $son5 = $mysql_model->Ylist("select * from `@#_yonghu` as y left join `@#_fanyong` as f on y.uid = f.uid  where  f.stuats = 1  and y.fid ='$s4[uid]' ");
                        $son5num += count($son5);
                        foreach ($son5 as $s5) {
                            if ($s5['mobile']) {
                                $son5_list .= '<a href='.LOCAL_PATH."/uname/".$s5[uid].".html >".$s5['mobile'] . "</a>,";
                            } else {
                                $son5_list .= '<a href='.LOCAL_PATH."/uname/".$s5[uid].".html >".$s5['email'] . "</a>,";
                            }
                            $alluser[$key]['user'] = $s5;
                            $alluser[$key]['level'] = 5;
                            $key++;
                            $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `type` = '$type' and `uid`='$huiyuan[uid]' and `fanyong_id` = $s5[uid]");
                            $son5price += $temp['price'];

                            $son6 = $mysql_model->Ylist("select * from `@#_yonghu` as y left join `@#_fanyong` as f on y.uid = f.uid  where  f.stuats = 1  and y.fid ='$s5[uid]' ");
                            $son6num += count($son6);
                            foreach ($son6 as $s6) {
                                if ($s6['mobile']) {
                                    $son6_list .= '<a href='.LOCAL_PATH."/uname/".$s6[uid].".html >".$s6['mobile'] . "</a>,";
                                } else {
                                    $son6_list .= '<a href='.LOCAL_PATH."/uname/".$s6[uid].".html >".$s6['email'] . "</a>,";
                                }
                                $alluser[$key]['user'] = $s6;
                                $alluser[$key]['level'] = 6;
                                $key++;
                                $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `type` = '$type' and `uid`='$huiyuan[uid]' and `fanyong_id` = $s6[uid]");
                                $son6price += $temp['price'];
                            }
                        }
                    }
                }
            }
        }

        $totalnum = $son2num + $son1num + $son3num + $son4num + $son5num + $son6num;

        $result['alluser'] = $alluser;
        $result['son1price'] = $son1price;
        $result['son2price'] = $son2price;
        $result['son3price'] = $son3price;
        $result['son4price'] = $son4price;
        $result['son5price'] = $son5price;
        $result['son6price'] = $son6price;

        $result['son1_list'] = $son1_list;
        $result['son2_list'] = $son2_list;
        $result['son3_list'] = $son3_list;
        $result['son4_list'] = $son4_list;
        $result['son5_list'] = $son5_list;
        $result['son6_list'] = $son6_list;

        $result['son1num'] = $son1num;
        $result['son2num'] = $son2num;
        $result['son3num'] = $son3num;
        $result['son4num'] = $son4num;
        $result['son5num'] = $son5num;
        $result['son6num'] = $son6num;
        $result['totalnum'] = $totalnum;
        return $result;
    }

    //申请返佣提现
    function fanyong_cash(){

		if(isset($_POST['J_submit'])){
			if($_POST['txtUserName']){
				$_POST['submit1'] = 1;
			}else{
				$_POST['submit2'] = 2;
			}
		}

        $mysql_model=System::DOWN_sys_class('model');
		$cashMoney = $mysql_model->YOne("select value from `@#_friend` where name='cashMoney'");
		$inviteCount = $mysql_model->YOne("select value from `@#_friend` where name='inviteCount'");
		$poundage = $mysql_model->YOne("select value from `@#_friend` where name = 'poundage'");
	
        $huiyuan=$this->userinfo;
        $uid = $huiyuan['uid'];
        $fmoney = $huiyuan['fmoney'];
        if(!$fmoney){
            $fmoney = 0;
        }
        if($fmoney >= 0){ //佣金提现金额限制可做修改。
            $cashouthdtotal = $fmoney;
        }else{
            $cashouthdtotal = 0;
        }
				

        if(isset($_POST['submit1'])){ //提现
			$money      = abs(intval($_POST['money']));
			$weername   =htmlspecialchars($_POST['txtUserName']);
			$bankname   =htmlspecialchars($_POST['txtBankName']);
			$branch     =htmlspecialchars($_POST['txtSubBank']);
			$banknumber =htmlspecialchars($_POST['txtBankNo']);
			$linkphone  =htmlspecialchars($_POST['txtPhone']);
			$time       =time();
			$cashType 	= 1;
			$type       = 1;  //佣金提现1/2余额转移
			$payType    = htmlspecialchars($_POST['payType']);
			$account	= htmlspecialchars($_POST['account']);
			$procefees  = $poundage['value'] / 100 * $money;
			
			$invite = $this->db->YOne("select count(*) as count from `@#_yonghu` where `yaoqing` = '$uid'");
			$result = $this->getAll();
			if($result['son1num'] < $inviteCount['value']){
				_notemobile("必须发展一级合伙人".$inviteCount['value']."人方可转到余额提现！");exit;
			}elseif($fmoney<$cashMoney['value']){
				_notemobile("佣金金额大于".$cashMoney['value']."元才能提现！");exit;
			}elseif($fmoney<$money ){
				_notemobile("输入额超出总佣金金额！");exit;
			}else{

				//插入提现申请表  这里不用在佣金表中插入记录 等后台审核才插入
				$this->db->Query("INSERT INTO `@#_yongjin_cashout`(`procefees`,`cashType`,`uid`,`money`,`username`,`bankname`,`branch`,`banknumber`,`linkphone`,`time`,`payType`,`account`)VALUES
		('$procefees','$cashType','$uid','$money','$weername','$bankname','$branch','$banknumber','$linkphone','$time','$payType','$account')");
				$fmoney = $huiyuan['fmoney'] -$money;
				$this->db->Query("UPDATE `@#_yonghu` SET `fmoney`=$fmoney WHERE `uid`='$uid' ");
				_notemobile("申请成功！请等待审核！");
			}
        }
		

        if(isset($_POST['submit2'])){//充值
            $money      = abs(intval($_POST['amount']));
			$type       = 1;
			$pay        ="账户";
			$time       =time();
			$content    ="返佣金额转移到账户";

			if($money <= 0 || $money > $fmoney){
				_notemobile("佣金金额输入不正确！");exit;
			}
			$result = $this->getAll();
			if($result['son1num'] < $inviteCount['value']){
				_notemobile("必须发展一级合伙人".$inviteCount['value']."人方可转到余额提现！");exit;
			}
			if($money <= 0 || $money > $fmoney){
				_notemobile("佣金金额输入不正确！");exit;
			}
			if($money<$cashMoney['value']){
				_notemobile("佣金必须满".$cashMoney['value']."方可转到余额提现！");exit;
			}

			//插入记录
			$account=$this->db->Query("INSERT INTO `@#_yonghu_zhanghao`(`uid`,`type`,`pay`,`content`,`money`,`time`)VALUES
		('$uid','$type','$pay','$content','$money','$time')");

			// 查询是否有该记录
			if($account){
				//修改剩余金额
				$leavemoney=$huiyuan['money']+$money;
				$fmoney = $huiyuan['fmoney'] -$money;
				$mrecode=$this->db->Query("UPDATE `@#_yonghu` SET `money`='$leavemoney',`fmoney`=$fmoney WHERE `uid`='$uid' ");
				//在佣金表中插入记录
				$recode=$this->db->Query("INSERT INTO `@#_fanyong_recodes`(`uid`,`type`,`content`,`money`,`time`)VALUES
		('$uid','-2','$content','$money','$time')");
				_notemobile("转移成功！");
			}else{
				_notemobile("转移失败！");
			}
        }

        $mysql_model=System::DOWN_sys_class('model');
        $huiyuan=$this->userinfo;
        $uid = $huiyuan['uid'];
        $recount=0;
        $fufen = System::DOWN_app_config("user_fufen",'','member');
        //查询提现记录
        //$recordarr=$mysql_model->Ylist("select * from `@#_yonghu_recodes` a left join `@#_yonghu_cashout` b on a.cashoutid=b.id where a.`uid`='$uid' and a.`type`='-3' ORDER BY a.`time` DESC");		$recordarr=

        $recordarr=$mysql_model->Ylist("select * from  `@#_yonghu_cashout`  where `uid`='$uid' ORDER BY `time` DESC limit 0,30");

        if(!empty($recordarr)){
            $recount=1;
        }
        include templates("mobile/user","fanyong_cash");


    }

//合伙人星级老板提现明细
	public function startcashlist(){
		$huiyuan = $this->userinfo;
		$uid = $huiyuan['uid'];
		$biaoti="星级佣金提现明细_"._yys("web_name");
		$envelopeCount = $this->db->YCount("select * from `@#_yongjin_cashout` where `payType` != '' and `uid`='$uid'");
		$fenye = System::DOWN_sys_class('page');
		if(isset($_GET['p'])){$fenyenum=$_GET['p'];}else{$fenyenum=1;}	
		$fenye->config($envelopeCount,10,$fenyenum,"0");		
		$envelopewithdrawlist = $this->db->YPage("select * from `@#_yongjin_cashout` where `payType` != '' and `uid`='$uid' ORDER BY id DESC",array("num"=>10,"page"=>$fenyenum,"type"=>1,"cache"=>0));

		include templates("mobile/user","startcashlist");
	}
//合伙人星级老板提现明细END
// pbluc function  by xfx
    function editor_safe_replace($content)
    {
        $tags = array(
            "'<iframe[^>]*?>.*?</iframe>'is",
            "'<frame[^>]*?>.*?</frame>'is",
            "'<script[^>]*?>.*?</script>'is",
            "'<head[^>]*?>.*?</head>'is",
            "'<title[^>]*?>.*?</title>'is",
            "'<meta[^>]*?>'is",
            "'<link[^>]*?>'is",
        );
        return preg_replace($tags, "", $content);
    }



    /* test  tree get all List
    function get_fanyong_son($slist,$huiyuan){
        $mysql_model=System::DOWN_sys_class('model');
        $price = 0;
        $son2num = 0;
        $result = array();
        foreach($slist as $s){
            if($s['mobile']){
                $son1_list = $s['mobile'].",";
            }else{
                $son1_list = $s['email'].",";
            }
            $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' and `fanyong_id` = $s[uid]");
            $price += $temp['price'];

            $son2=$mysql_model->Ylist("select * from `@#_yonghu` where `fid`='$s[uid]'");
            $slist[$s]['son2'] = $son2;
            $son2num += count($son2);

        }
        $result['price'] = $price;
        $result['nextnum'] = $son2num;
        $result['son2_list'] = $slist;
    }

    // $uid = huiyuan id
    // return num => totalnum,son1num,son2num...
    //        list=> son1_list,son2_list...
    function get_fanyong($uid){
        $mysql_model=System::DOWN_sys_class('model');
        //查询返佣信息
        $son1=$mysql_model->Ylist("select * from `@#_yonghu` where `fid`='$uid' ");
        $son1num = count($son1);
        $son2num = 0;
        $son3num = 0;
        $son4num = 0;
        $son5num = 0;
        $son6num = 0;
        $result = array();

        $son1_list = $son2_list = $son3_list = $son4_list =$son5_list =$son6_list = "";

        $son1price = $son2price = $son3price = $son4price = $son5price = $son6price = 0;

        foreach($son1 as $s1){
            if($s1['mobile']){
                $son1_list = $s1['mobile'].",";
            }else{
                $son1_list = $s1['email'].",";
            }
            $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' and `fanyong_id` = $s1[uid]");
            $son1price += $temp['price'];

            $son2=$mysql_model->Ylist("select * from `@#_yonghu` where `fid`='$s1[uid]'");
            $son2num += count($son2);
            foreach($son2 as $s2){
                if($s2['mobile']){
                    $son2_list = $s2['mobile'].",";
                }else{
                    $son2_list = $s2['email'].",";
                }
                $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' and `fanyong_id` = $s2[uid]");
                $son2price += $temp['price'];

                $son3=$mysql_model->Ylist("select * from `@#_yonghu` where `fid`='$s2[uid]' ");
                $son3num += count($son3);
                foreach($son3 as $s3){
                    if($s3['mobile']){
                        $son3_list = $s3['mobile'].",";
                    }else{
                        $son3_list = $s3['email'].",";
                    }
                    $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' and `fanyong_id` = $s3[uid]");
                    $son3price += $temp['price'];

                    $son4=$mysql_model->Ylist("select * from `@#_yonghu` where `fid`='$s3[uid]' ");
                    $son4num += count($son4);
                    foreach($son4 as $s4){
                        if($s4['mobile']){
                            $son4_list = $s4['mobile'].",";
                        }else{
                            $son4_list = $s4['email'].",";
                        }
                        $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' and `fanyong_id` = $s4[uid]");
                        $son4price += $temp['price'];

                        $son5=$mysql_model->Ylist("select * from `@#_yonghu` where `fid`='$s4[uid]' ");
                        $son5num += count($son5);
                        foreach($son5 as $s5){
                            if($s5['mobile']){
                                $son5_list = $s5['mobile'].",";
                            }else{
                                $son5_list = $s5['email'].",";
                            }
                            $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' and `fanyong_id` = $s5[uid]");
                            $son5price += $temp['price'];

                            $son6=$mysql_model->Ylist("select * from `@#_yonghu` where `fid`='$s5[uid]' ");
                            $son6num += count($son6);
                            foreach($son6 as $s6){
                                if($s6['mobile']){
                                    $son6_list = $s6['mobile'].",";
                                }else{
                                    $son6_list = $s6['email'].",";
                                }
                                $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' and `fanyong_id` = $s6[uid]");
                                $son6price += $temp['price'];
                            }
                        }
                    }
                }
            }
        }

        $totalnum = $son2num + $son1num + $son3num + $son4num + $son5num + $son6num;
        $result['num']['totalnum'] = $totalnum;
        $result['num']['son1num'] = $son1num;
        $result['num']['son2num'] = $son2num;
        $result['num']['son3num'] = $son3num;
        $result['num']['son4num'] = $son4num;
        $result['num']['son5num'] = $son5num;
        $result['num']['son6num'] = $son6num;
        $result['list']['son1_list'] = $son1_list;
        $result['list']['son2_list'] = $son2_list;
        $result['list']['son3_list'] = $son3_list;
        $result['list']['son4_list'] = $son4_list;
        $result['list']['son5_list'] = $son5_list;
        $result['list']['son6_list'] = $son6_list;
        $result['price']['son1_price'] = $son1price;
        $result['price']['son2_price'] = $son2price;
        $result['price']['son3_price'] = $son3price;
        $result['price']['son4_price'] = $son4price;
        $result['price']['son5_price'] = $son5price;
        $result['price']['son6_price'] = $son6price;
        return $result;
    }*/
    public function upimage(){

        //System::DOWN_App_class('Uploader','','no');
        //上传图片框中的描述表单名称，
        //$biaoti = htmlspecialchars($_POST['pictitle'], ENT_QUOTES);
        //$path = htmlspecialchars($_POST['dir'], ENT_QUOTES);

        if(!isset($_POST['pictitle']) && !isset($_FILES['upfile'])){
            exit;
        }
        $biaoti = $_POST['pictitle'];
        $path=YYS_UPLOADS.'shopimg/';
        System::DOWN_sys_class('upload','sys','no');
        upload::upload_config(array('png','jpg','jpeg','gif'),500000,'shopimg');
        upload::go_upload($_FILES['upfile']);

        if(!upload::$ok){
            $url='';
            $biaoti=$biaoti;
            $originalName='';
            $state=upload::$error;
        }else{
            $url=YYS_UPLOADS_PATH.'/shopimg/'.upload::$filedir."/".upload::$filename;
            $biaoti=$biaoti;
            $originalName='';
            $state='SUCCESS';
        }
        echo "{'url':'".$url."','title':'".$biaoti."','original':'".$originalName."','state':'".$state ."'}";
        //{'url':'upload/20130728/13749880933714.jpg','title':'梨花.jpg','original':'梨花.jpg','state':'SUCCESS'}

    }

	//星级开始
	public function start(){ 
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
        $result = $this->getAll('1');
        $biaoti="星级合伙人管理 - "._yys("web_name");
        $summoney = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `type` = '1' and `uid`='$huiyuan[uid]' ");
        $summoney = $summoney['price'];
        $zongji=$this->db->YCount("select * from `@#_fanyong_list` where `type` = '1' and `uid`='$huiyuan[uid]' ");
        $fenye=System::DOWN_sys_class('page');
        if(isset($_GET['p'])){$fenyenum=$_GET['p'];}else{$fenyenum=1;}
        $fenye->config($zongji,10,$fenyenum,"0");
        $list = $this->db->YPage("select * from `@#_fanyong_list` where `type` = '1' and `uid`='$huiyuan[uid]'  ORDER BY id DESC",array("num"=>10,"page"=>$fenyenum,"type"=>1,"cache"=>0));
        foreach($list as $v => $k){
            $user=$mysql_model->YOne("select email,mobile from `@#_yonghu` where `uid`='$k[fanyong_id]' ");
            if($user['mobile']){
                $list[$v]['name'] = $user['mobile'];
            }else{
                $list[$v]['name'] = $user['email'];
            }
            $ucount = $mysql_model->YOne("select count(*) as count from `@#_fanyong_list` f2 where f2.`type` = '1' and f2.fanyong_id='$k[fanyong_id]' and f2.uid = $huiyuan[uid] and f2.fanyong_time <= $k[fanyong_time]");
            $list[$v]['count'] = $ucount['count'];
			$yonghu = $mysql_model->YOne("select * from `@#_yonghu` where `uid` = '$k[fanyong_id]'");
			$list[$v]['grade'] = intval($yonghu['grade']);
        }
		
        $listcount = count($list);
		
		//取得所有的下线
		$nextCount = $mysql_model->YCount("select * from `@#_yonghu` where `yaoqing` = '$huiyuan[uid]'");
        include templates("mobile/user","startlist");
	}

	public function userzzorderlist(){
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$uid = $huiyuan['uid'];
		$biaoti="供应商订单管理 - "._yys("web_name");		
		
		$zongji=$this->db->YCount("select * from `@#_yonghu_yys_record` where `supplierId`='$uid' and `isSupplier` = '1'  and `huode` > '10000000' order by `id` DESC");
		$fenye=System::DOWN_sys_class('page');
		if(isset($_GET['p'])){$fenyenum=$_GET['p'];}else{$fenyenum=1;}	
		$fenye->config($zongji,10,$fenyenum,"0");		
		$record = $this->db->YPage("select * from `@#_yonghu_yys_record` where `supplierId`='$uid' and `isSupplier` = '1'  and `huode` > '10000000' order by `id` DESC",array("num"=>10,"page"=>$fenyenum,"type"=>1,"cache"=>0));
		
		include templates("mobile/user","userzzorderlist");
	}

	public function get_dingdan(){
		$id = $this->segment(4);
		$type = $this->segment(5);
		if($type == 1){
			$table = '_zg_yonghu_yys_record';
		}else{
			$table = '_yonghu_yys_record';
		}
		$biaoti="供应商订单发货 - "._yys("web_name");	
		$record = $this->db->YOne("select * from `@#$table` where `id` = '$id'");
		
		if (!$record)
            _notemobile("参数不正确!");

        if (isset($_POST['submit'])) {
			
			if($record['status'] == '已付款,已发货,待收货'){
				_notemobile("已发货的订单不能重复发货！", LOCAL_PATH . "/mobile/home/userzzorderlist", 3);
			}
			if($record['status'] == '已付款,已发货,已完成'){
				_notemobile("已完成的订单不能更改！", LOCAL_PATH . "/mobile/home/userzzorderlist", 3);
			}

            $record_code = explode(",", $record['status']);
            $status = $_POST['status'];
            $company = $_POST['company'];
            $company_code = $_POST['company_code'];
            $company_money = floatval($_POST['company_money']);
            $code = abs(intval($_POST['code']));
            if (!$company_money) {
                $company_money = '0.01';
            } else {
                $company_money = sprintf("%.2f", $company_money);
            }

            if ($status == '未完成') {
                $status = $record_code[0] . ',' . $record_code[1] . ',' . '未完成';
            }
            if ($status == '已发货') {
                $status = '已付款,已发货,待收货';
            }
            if ($status == '未发货') {
                $status = '已付款,未发货,未完成';
            }
            if ($status == '已完成') {
                $status = '已付款,已发货,已完成';
            }
            if ($status == '已作废') {
                $status = $record_code[0] . ',' . $record_code[1] . ',' . '已作废';
            }

            $ret = $this->db->Query("UPDATE `@#$table` SET `status`='$status',`company` = '$company',`company_code` = '$company_code',`company_money` = '$company_money' where id='$code'");
            if ($ret) {
				if($status == '已付款,已发货,待收货'){
					$record = $this->db->YOne("SELECT * FROM `@#$table` where `id`='$code'");
					$userinfo = $this->db->YOne("select * from `@#_yonghu` where `uid` = '$record[uid]'");
					$returnConfig = System::DOWN_App_config("commision","","admin");
					$pushData = array(
						'username' => $userinfo['username'],
						'webname' => _yys("web_name"),
						'shopname' => $record['shopname'],
						'days' => $returnConfig['commisionDay'],
						'expressName' => $record['company'],
						'expressCode' => $record['company_code']
					);
					push_wx_msg_new('fhtz',$userinfo['openid'],$pushData);
				}
				_notemobile("订单发货成功", LOCAL_PATH . "/mobile/home/userzzorderlist", 3);
            } else {
                _notemobile("更新失败");
            }
        }

        System::DOWN_sys_fun("user");
        $uid = $record['uid'];
        $weer = $this->db->YOne("select * from `@#_yonghu` where `uid` = '$uid'");
		//地址库中的地址显示会员默认地址
        $weer_dizhi2 = $this->db->YOne("select * from `@#_yonghu_dizhi` where `uid` = '$uid' and `default` = 'Y'");
        $weer_dizhi = $this->db->YOne("select * from `@#_yonghu_yys_record` where `uid` = '$uid' and `id` = '$code'");
        $go_time = $record['time'];
		
		include templates("mobile/user","get_dingdan");
	}

	
	/*
	*	升级星级
	*/
	public function startAdd(){
		$distribution = System::DOWN_app_config("distribution",'','member');
		$grade = $this->segment(4);

		if($grade){
			$huiyuan = $this->userinfo;
			$uid = $huiyuan['uid'];
			if($grade <= $huiyuan['grade']){
				_notemobile("将要升级的等级低于现有的等级", LOCAL_PATH . "/member/home/startAdd", 3);
			}
			if($grade == 1){
				$key = 'firstStart';
				$keyName = '一星会员';
			}elseif($grade == 2){
				$key = 'secondStart';
				$keyName = '二星会员';
			}elseif($grade == 3){
				$key = 'thirdStart';
				$keyName = '三星会员';
			}
			
			$needMoney = $distribution[$key];

			if($needMoney > $huiyuan['money']){
				_notemobile("申请失败，您的余额低于" . $needMoney . '元，请先充值', LOCAL_PATH . "/mobile/home/userrecharge", 3);
			}else{
				
				//升级星级
				//扣钱先
				$money = $huiyuan['money'] - $needMoney;
				$sql = "UPDATE `@#_yonghu` set `money` = '$money' where uid = '$uid'";
				$res = $this->db->Query($sql);
				if($res){
					//进行对应升级
					$upGrade = "UPDATE `@#_yonghu` SET `grade` = '$grade' WHERE `uid` = '$uid'";
					$res = $this->db->Query($upGrade);

					//进行返佣
					$this->upGradeDistributions($res,$grade);
					
					$time = time();
					$this->db->Query("INSERT INTO `@#_yonghu_zhanghao`(`uid`,`type`,`pay`,`content`,`money`,`time`)VALUES
					('$uid','-1','账户','购买".$keyName."',$needMoney,'$time')");
					_notemobile("祝贺您，升级成功", LOCAL_PATH . "/mobile/home/startAdd", 3);
				}else{
					_notemobile("申请失败，请重试或联系管理员", LOCAL_PATH . "/mobile/home/startAdd", 3);
				}
			}
		}
		
		$huiyuan = $this->userinfo;
        $biaoti="升级星级";
        include templates("mobile/user","startadd");
	}
	
	
	
	//升级返还函数
	public function upGradeDistributions($type=null,$grade){
		$uid = $this->userinfo['uid'];
		
		//引入配置文件
		$costConfig = System::DOWN_App_config("distribution","","member");


		if($costConfig['disOpen']){
			
			//先判断当前的用户是否已经升级到3级，到3级后不再升级
			if($this->userinfo['grade'] <= '3'){
				
				$res = false;
				
				//这里区分出是直接购买还是累计升级
				if($costConfig['gradeCondition'] == 'buy'){
					//直接购买就直接传递
					if($type){
						$res = true;
					}
				}elseif($costConfig['gradeCondition'] == 'charge'){
					//先查看本人是否升级
					$userCharge = $this->db->YOne("select sum(`money`) as `money` from `@#_yonghu_addmoney_record` where `uid` = '$uid' and `status` = '已付款'");
					$userCharge = $userCharge['money'];
					

					//判断升级参数
					if($userCharge >= $costConfig['firstStart'] && $userCharge < $costConfig['secondStart']){
						$grade = 1;
					}elseif($userCharge >= $costConfig['secondStart'] && $userCharge < $costConfig['thirdStart']){
						$grade = 2;
					}elseif($userCharge >= $costConfig['thirdStart']){
						$grade = 3;
					}else{
						$grade = 0;
					}

					if($grade > 0 && $this->userinfo['grade'] < $grade){
						//进行对应升级
						$upGrade = "UPDATE `@#_yonghu` SET `grade` = '$grade' WHERE `uid` = '$uid'";
						$res = $this->db->Query($upGrade);
					}
				}

				//如果存在升级，则进行对应的返还
				if($res){
				
					$openid = $this->db->YOne("select `openid` from `@#_yonghu` where `uid` = '$uid'");
					if($openid['openid']){
						$username = $this->db->YOne("select `username` from `@#_yonghu` where `uid` = '$uid'");
						$pushData = array(
							'username' => $username['username'],
							'jibie' => $grade,
						);

						push_wx_msg_new('xjts',$openid['openid'],$pushData);
					}

					//查询出上级
					$inviteId = $this->userinfo['yaoqing'];

					//查询上级现在的等级
					$inviteUser = $this->db->YOne("select * from `@#_yonghu` where `uid` = '$inviteId'");

					//如果是3级则获取当前客户升级等级的全部返还
					//等级是3，无限制，返还全部
					if($inviteUser['grade'] == '3'){
						if($grade == 1){
							//查询是否对本下级返还过
							$nowUserMargin = $this->db->YOne("select * from `@#_fanyong_recodes` where `inviteMargin` = '1' and `uid` = '$inviteId' and `inviteId` = '$uid'");
							if(!$nowUserMargin){
								//基础参数
								$content = "合伙人升级一星返佣";
								$money = $costConfig['firstMargin'];
								$ygmoney = $costConfig['firstStart'];
							}
						}elseif($grade == 2){
							//查询是否对本下级返还过
							$nowUserMargin = $this->db->YOne("select * from `@#_fanyong_recodes` where `inviteMargin` = '2' and `uid` = '$inviteId' and `inviteId` = '$uid'");
							if(!$nowUserMargin){
								//基础参数
								$content = "合伙人升级二星返佣";
								$money = $costConfig['secondMargin'];
								$ygmoney = $costConfig['secondStart'];
							}
						}elseif($grade == 3){
							//查询是否对本下级返还过
							$nowUserMargin = $this->db->YOne("select * from `@#_fanyong_recodes` where `inviteMargin` = '3' and `uid` = '$inviteId' and `inviteId` = '$uid'");
							if(!$nowUserMargin){
								//基础参数
								$content = "合伙人升级三星返佣";
								$money = $costConfig['thirdMargin'];
								$ygmoney = $costConfig['thirdStart'];
							}
						}
					}elseif($inviteUser['grade'] == 2){
						
						//上线为2级时，只能获得1级的全部奖励以及3个2级
						if($grade == 1){
							//查询是否对本下级返还过
							$nowUserMargin = $this->db->YOne("select * from `@#_fanyong_recodes` where `inviteMargin` = '1' and `uid` = '$inviteId' and `inviteId` = '$uid'");
							if(!$nowUserMargin){
								//基础参数
								$content = "合伙人升级一星返佣";
								$money = $costConfig['firstMargin'];
								$ygmoney = $costConfig['firstStart'];
							}
						}elseif($grade == 2){
							
							//查询是否对此级返还过
							$firstMarginOk = $this->db->YList("select * from `@#_fanyong_recodes` where `inviteMargin` = '2' and `uid` = '$inviteId'");
							$countFirstMargin = count($firstMarginOk);
													
							//查询是否对本下级返还过
							$nowUserMargin = $this->db->YOne("select * from `@#_fanyong_recodes` where `inviteMargin` = '2' and `uid` = '$inviteId' and `inviteId` = '$uid'");
							
							if(!$nowUserMargin && $countFirstMargin <= $costConfig['secondMarginNum']){
								//如返还已经到设置限额，则不再返还
								//基础参数
								$content = "合伙人升级二星返佣";
								$money = $costConfig['secondMargin'];
								$ygmoney = $costConfig['secondStart'];
							}
						}
					}elseif($inviteUser['grade'] == 1){
						//上线为1级时，只能获得1级的3个，其他等级不管
						if($grade == 1){
							
							//查询是否对此级返还过
							$firstMarginOk = $this->db->YList("select * from `@#_fanyong_recodes` where `inviteMargin` = '1' and `uid` = '$inviteId'");
							$countFirstMargin = count($firstMarginOk);
							
							//查询是否对本下级返还过
							$nowUserMargin = $this->db->YOne("select * from `@#_fanyong_recodes` where `inviteMargin` = '1' and `uid` = '$inviteId' and `inviteId` = '$uid'");
							
							if(!$nowUserMargin && $countFirstMargin <= $costConfig['firstMarginNum']){
								//基础参数
								$content = "合伙人升级一星返佣";
								$money = $costConfig['firstMargin'];
								$ygmoney = $costConfig['firstStart'];
							}
						}
					}

					//金额非0，则进行返还
					if($money > 0){
											
						//进行返还，先入库到会员账户明细
						$time = time();
						$noteSql  = "INSERT INTO `@#_fanyong_recodes` (`uid`,`type`,`content`,`money`,`time`,`ygmoney`,`inviteId`,`inviteMargin`) VALUES ";
						$noteSql .= "('$inviteId','1','$content','$money','$time','$ygmoney','$uid','$grade')";
						$res = $this->db->Query($noteSql);
						//echo $noteSql;
						//echo "<br/>";
						if($res){
							//写入LIST
							$fanyongSql = "INSERT INTO `@#_fanyong_list` (`uid`,`fanyong_id`,`price`,`fanyong_time`,`type`) VALUES ('$inviteId','$uid','$money','$time','1')";
							$res = $this->db->Query($fanyongSql);
							//echo $fanyongSql;
							//echo "<br/>";
							//更新对应会员的佣金
							if($res){
								$updateSql = "UPDATE `@#_yonghu` SET `fmoney` = `fmoney` + '$money' WHERE `uid` = '$inviteId'";
								$this->db->Query($updateSql);
								
								$pushData = array(
									'username' => $this->userinfo['username'],
									'jibie' => $grade,
									'money' => $money,
								);
								push_wx_msg_new('xxsjfy',$inviteUser['openid'],$pushData);
								//echo $updateSql;
							}
						}
					}
				}
			}
		}
	}
	
	public function envelope(){
		$huiyuan = $this->userinfo;
        $biaoti="升级星级";
        include templates("mobile/user","envelope");
	}
//商户自助发布商品
	public function userzzzgadd(){
        $huiyuan = $this->userinfo;
        $uid = $huiyuan['uid'];
        $mysql_model=System::DOWN_sys_class('model');
		$biaoti="发布商品";
		$gradeConfig = System::DOWN_App_config("user_gyszg","","admin");
		$yonghuzzg = $mysql_model->YOne("select * from `@#_yonghu_zzzg` where `uid` = '$uid'");
		$goodNum = $mysql_model->YOne("select count(*) as count from `@#_zg_shangpin` where `uid` = '$uid'");
	
		if($gradeConfig[$yonghuzzg['supplyGrade'].'GoodsNum'] < $goodNum['count']){
			_note('发布数量已到最大个数');
		}elseif(time() > $yonghuzzg['supplyGradeTime']){
			_note('您的会员已到期，请及时续费');
		}
		
		if(isset($_POST['dosubmit'])){
			
			$cateid = intval($_POST['cateid']);
			$pinpaiid = intval($_POST['brand']);
			$biaoti = _htmtguolv($_POST['title']);
			$biaoti_color = htmlspecialchars($_POST['title_style_color']);
			$biaoti_bold = htmlspecialchars($_POST['title_style_bold']);
			$biaoti2 = _htmtguolv($_POST['title2']);
						
			$guanjianzi = htmlspecialchars($_POST['keywords']);
			$miaoshu = htmlspecialchars($_POST['description']);
			$content = $this->editor_safe_replace(stripslashes($_POST['content']));
			$money = intval($_POST['money']);
			$yunjiage = intval($_POST['yunjiage']);
			$thumb = htmlspecialchars($_POST['thumb']);		
			$maxqishu = intval($_POST['maxqishu']);			
			$canyurenshu = 0;		
			$shangpinss_key_pos = isset($_POST['goods_key']['pos']) ? 1 : 0;
			$shangpinss_key_renqi = isset($_POST['goods_key']['renqi']) ? 1 : 0;
			$shangpinss_key_renqi1 = isset($_POST['goods_key']['renqi1']) ? 1 : 0;
			
			$supplierPercent = floatval($_POST['supplierPercent']);
			
			$cashBack 	= floatval($_POST['cashBack']);
			$costPrice	= $_POST['costPrice'];
			$sendUrl 	= $_POST['sendUrl'];
			$taobaoUrl 	= $_POST['taobaoUrl'];

			
			$mainWord = $_POST['mainWord'];
			$wordType = $_POST['wordType'];

			$subWord = array();
			foreach($mainWord as $key => $one){
				$subWord[$key]['ids'] = $key;
				$subWord[$key]['name'] = $one;
				$subWord[$key]['type'] = $wordType[$key];
				$subWord[$key]['sub'] = $_POST["sub_$key"];
			}
			$newTypes = serialize($subWord);

			if(!$biaoti)_note("标题不能为空");
			if(!$money)_note("价格不能为空");
			if(!$supplierPercent || $supplierPercent <= 0)_note("佣金比例不能为空");
			if(!$remote_url) {
				if (!$thumb) _note("你未上传远程地址，所以缩略图不能为空");
			}

			if(isset($_POST['uppicarr'])){
				$picarr = serialize($_POST['uppicarr']);
			}else{
				$picarr = serialize(array());
			}




			if($_POST['xsjx_time'] != ''){
				$xsjx_time = strtotime($_POST['xsjx_time']) ? strtotime($_POST['xsjx_time']) : time();
				$xsjx_time_h = intval($_POST['xsjx_time_h']) ? $_POST['xsjx_time_h'] : 36000;
				$xsjx_time += $xsjx_time_h;
			}else{
				$xsjx_time = '0';
			}


			if($maxqishu > 65535){
				_note("最大期数不能超过65535期");
			}


			$time=time();	//添加时间
			$mysql_model->tijiao_start();
			$query_1 = $mysql_model->Query("INSERT INTO `@#_sqfb` (`quyu_begin`,`quyu_end`,`ka`,`mi`,`cateid`, `brandid`, `title`, `title_style`, `title2`, `keywords`, `description`, `money`, `yunjiage`, `zongrenshu`, `canyurenshu`,`shenyurenshu`, `qishu`,`maxqishu`,`thumb`, `picarr`, `content`,`xsjx_time`,`renqi`,`renqi1`,`pos`, `time`, `cardId`, `cardId1`, `cardPwd`, `leixing`,`yuanjia`,`uid`,`expressFee`,`cashBack`,`costPrice`,`sendUrl`,`taobaoUrl`,`newTypes`) VALUES ( '$quyu_begin','$quyu_end','".htmlspecialchars($_POST['kahao'])."','".htmlspecialchars($_POST['mima'])."','$cateid', '$pinpaiid', '$biaoti', '$biaoti_style', '$biaoti2', '$guanjianzi', '$miaoshu', '$money', '$yunjiage', '$zongrenshu', '$canyurenshu','$shenyurenshu', '1','$maxqishu', '$thumb', '$picarr', '$content','$xsjx_time','$shangpinss_key_renqi','$shangpinss_key_renqi1', '$shangpinss_key_pos','$time','$cardId','$cardId1','$cardPwd','$goods_key_leixing','$cardId2','$uid','$expressFee','$cashBack','$costPrice','$sendUrl','$taobaoUrl','$newTypes')");
			$shopid = $mysql_model->last_id();
			//$query_1 = $mysql_model->Query("INSERT INTO `@#_sqfb` (`title`, `description`, `money`, `supplierPercent`, `maxqishu`,`thumb`, `picarr`, `content`,`xsjx_time`,`time`,`uid`,`remote_url`,`newTypes`) VALUES ( '$biaoti', '$miaoshu', '$supplierPercent', '$yongjin', '$maxqishu', '$thumb', '$picarr','$content','$xsjx_time','$time',$uid,'$remote_url','$newTypes')");
		  if($query_1){
				$mysql_model->tijiao_commit();
				_note("申请成功，请等待审核",LOCAL_PATH."/member/home",3);
			}else{

				$mysql_model->tijiao_rollback();
				_note("申请失败，请重试或联系管理员",LOCAL_PATH."/member/home",3);
			}


		}else {
		   
			$this->categoryszg=$this->db->Ylist("SELECT * FROM `@#_zg_fenlei` WHERE `model` = '1' order by `parentid` ASC,`cateid` ASC",array('key'=>'cateid'));
			$cateid=intval($this->segment(4));		
			$fenleis=$this->categoryszg;
			$tree=System::DOWN_sys_class('tree');
			$tree->icon = array('│ ','├─ ','└─ ');
			$tree->nbsp = '&nbsp;';
			$fenleishtml="<option value='\$cateid'>\$spacer\$name</option>";
			$tree->init($fenleis);	
			$fenleishtml=$tree->get_tree(0,$fenleishtml);
			$fenleishtml='<option value="0">≡ 请选择栏目 ≡</option>'.$fenleishtml;
			if($cateid){			
				$cateinfo=$this->db->YOne("SELECT * FROM `@#_zg_fenlei` WHERE `cateid` = '$cateid' LIMIT 1");
				if(!$cateinfo)_note("参数不正确,没有这个栏目",G_ADMIN_PATH.'/'.DOWN_C.'/addarticle');
				$fenleishtml.='<option value="'.$cateinfo['cateid'].'" selected="true">'.$cateinfo['name'].'</option>';			
			}		

			  
            $this->zzfb = $mysql_model->YOne("SELECT * from `@#_yonghu_zzzg` where `uid` = '$uid'");
            $zzfb = $this->zzfb;
			include templates("mobile/user","userzzzgadd");
        }
    }
	
	public function userzzzgorderlist(){
		$mysql_model=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$uid = $huiyuan['uid'];
		$biaoti="供应商订单管理 - "._yys("web_name");		
		
		$zongji=$this->db->YCount("select * from `@#_zg_yonghu_yys_record` where `supplierId`='$uid' and `isSupplier` = '1' order by `id` DESC");
		$fenye=System::DOWN_sys_class('page');
		if(isset($_GET['p'])){$fenyenum=$_GET['p'];}else{$fenyenum=1;}	
		$fenye->config($zongji,10,$fenyenum,"0");		
		$record = $this->db->YPage("select * from `@#_zg_yonghu_yys_record` where `supplierId`='$uid' and `isSupplier` = '1' order by `id` DESC",array("num"=>10,"page"=>$fenyenum,"type"=>1,"cache"=>0));
		
		include templates("mobile/user","userzzzgorderlist");
	}
	
	public function coupon(){
		$mysql_model = System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$uid = $huiyuan['uid'];
		$biaoti="我的代金券 - "._yys("web_name");		
		
		$zongji=$this->db->YCount("select * from `@#_coupon_yonghu_yys_record` where `uid`='$uid' order by `id` DESC");
		$fenye=System::DOWN_sys_class('page');
		if(isset($_GET['p'])){$fenyenum=$_GET['p'];}else{$fenyenum=1;}	
		$fenye->config($zongji,10,$fenyenum,"0");		
		$record = $this->db->YPage("select * from `@#_coupon_yonghu_yys_record` where `uid`='$uid' order by `id` DESC",array("num"=>10,"page"=>$fenyenum,"type"=>1,"cache"=>0));

		foreach($record as $key => $one){
			$platform = $this->db->YOne("select platform from `@#_coupon` where `id` = '$one[couponId]'");
			$record[$key]['platform'] = $platform['platform'];
		}
		include templates("mobile/user","coupon");
	}
	
	public function get_dingdan_coupon(){
		$id = $this->segment(4);
		$huiyuan=$this->userinfo;
		$record = $this->db->YOne("select * from `@#_coupon_yonghu_yys_record` where `id` = '$id'");
		if (!$record)
            _note("参数不正确!");
		$coupon = $this->db->YOne("select * from `@#_coupon` where `id` = '$record[coup]'");

		$couponCode = $this->db->YOne("select * from `@#_coupon_code` where `id` = '$record[cardId]'");
        if (isset($_POST['submit'])) {
			if($record['status'] == '已付款,已发货,待收货'){
				_note('已发货的不能重复发货！');
			}

			if($record['status'] == '已付款,已发货,已完成'){
				_note('已完成的不能更改！');
			}
            $record_code = explode(",", $record['status']);
            $status = $_POST['status'];
            $company = $_POST['company'];
            $company_code = $_POST['company_code'];
            $company_money = floatval($_POST['company_money']);
            $code = abs(intval($_POST['code']));
            if (!$company_money) {
                $company_money = '0.01';
            } else {
                $company_money = sprintf("%.2f", $company_money);
            }

            if ($status == '未完成') {
                $status = $record_code[0] . ',' . $record_code[1] . ',' . '未完成';
            }
            if ($status == '已发货') {
                $status = '已付款,已发货,待收货';
            }
            if ($status == '未发货') {
                $status = '已付款,未发货,未完成';
            }
            if ($status == '已完成') {
                $status = '已付款,已发货,已完成';
            }
            if ($status == '已作废') {
                $status = $record_code[0] . ',' . $record_code[1] . ',' . '已作废';
            }

            $ret = $this->db->Query("UPDATE `@#$table` SET `status`='$status',`company` = '$company',`company_code` = '$company_code',`company_money` = '$company_money' where id='$code'");
            if ($ret) {
				if($status == '已付款,已发货,待收货'){
					$record = $this->db->YOne("SELECT * FROM `@#$table` where `id`='$code'");
					$userinfo = $this->db->YOne("select * from `@#_yonghu` where `uid` = '$record[uid]'");
					$returnConfig = System::DOWN_App_config("commision","","admin");
					$pushData = array(
						'username' => $userinfo['username'],
						'webname' => _yys("web_name"),
						'shopname' => $record['shopname'],
						'days' => $returnConfig['commisionDay'],
						'expressName' => $record['company'],
						'expressCode' => $record['company_code']
					);
					push_wx_msg_new('fhtz',$userinfo['openid'],$pushData);
				}
                _note("更新成功");
            } else {
                _note("更新失败");
            }
        }

        System::DOWN_sys_fun("user");
        $uid = $record['uid'];
        $weer = $this->db->YOne("select * from `@#_yonghu` where `uid` = '$uid'");
		//地址库中的地址显示会员默认地址
        $weer_dizhi2 = $this->db->YOne("select * from `@#_yonghu_dizhi` where `uid` = '$uid' and `default` = 'Y'");
        $weer_dizhi = $this->db->YOne("select * from `@#_coupon_yonghu_yys_record` where `uid` = '$uid' and `id` = '$code'");
        $go_time = $record['time'];
		include templates("mobile/user","get_dingdan_coupon");
	}
	
	
	/*银行管理列表*/
	public function banklist(){
		$huiyuan = $this->userinfo;
		$header = '轻松管理我的卡号账号<br/><div style="margin-top:-10px;">工作人员不会向您索取密码和验证信息，请注意安全！</div>';
		include templates("mobile/user","banklist");
	}
	
	/*新建银行*/
	public function bankset(){
		$huiyuan = $this->userinfo;
		$header = '添加多个备用卡账号，提现更方便';
		include templates("mobile/user","bankset");
	}
	
	/*查看物流*/
	public function express(){
		$huiyuan = $this->userinfo;
		$order_sn = $this->segment(4);
		$order = $this->db->YOne("select * from `@#_order_list` where `order_sn` = '$order_sn'");
		$express = $this->db->YOne("select * from `@#_express_list` where `id` = '$order[express_id]'");
		$company_name = $this->db->YOne("select * from `@#_express_company` where `id` = '$express[express_id]'");
		$express['company_name'] = $company_name['name'];
		include templates("mobile/user","express");
	}
	/*我要评价*/
	public function assess(){
		$huiyuan = $this->userinfo;
		$order_sn = $this->segment(4);
		$order = $this->db->YOne("select * from `@#_order_list` where `order_sn` = '$order_sn'");
		if(!$order || !$order_sn){
			_note("不存在的订单");
		}
		$comment = $this->db->YOne("select * from `@#_comment` where `oid` = '$order[id]'");
		include templates("mobile/user","assess");
	}
}

?>